# compose-android

Tim Malseed

03/29/2023, 12:55 AM
I’m writing a UI test for compose, and attempting to assert that a node exists. The app renders a ‘loading’ state, until the user is signed in, and then navigates to a ‘login’ screen. The assertion that the ‘loading’ node is rendered seems to fail though. I think it’s because under test, there’s no real delay between loading and login, so perhaps the transition happens too quickly, and as far as the test is concerned, the loading node doesn’t exist! Does this just call for disabling automatic synchonization? Part of me wonders if maybe the test dispatcher skipping delays causes the UI test to execute in a sort of unrealistic environment
The states that are rendered are based on a flow. I can delay each emission in the flow by some arbitrary amount (say 500ms), set
mainClock.autoAdvance = false
, advance by <500ms, perform the assertion, and then set
mainClock.autoAdvance = true
. But, it feels like I’m creating a sort of brittle test. If that delay changes, the test will fail

Alex Vanyo

03/31/2023, 12:11 AM
I think it’s because under test, there’s no real delay between loading and login
There’s not necessarily any guarantee that in production you’ll ever see the “loading” state either if it goes from “loading” to “loaded” immediately You could sort of think of your entire UI as a giant
in the sense that intermediate states might not render, just the last one. If you have Compose code that requires composing with one state before recomposing with another, there’s probably something a bit weird going on. Agreed that messing with time dispatching in tests is probably brittle, I’d probably aim towards something like
Copy code
// kick off the request but don't let it finish

// assert loading state is correct

// manually allow request to finish and become loaded

// assert loaded state is correct

Tim Malseed

03/31/2023, 12:12 AM
That makes sense, thanks Alex