androidandroid-jetpack-composeandroid-testinggui-testing

Keep Compose UI test waiting without freezing thread


Is this possible during test to wait N amount of time, without freezing main thread. I am testing Compose app, and not sure how to do it. For now I use :

Thread.sleep(timeoutMs:Long)

But app just freeze and incoming data not displayed, since it Compose for Wear Os, so I can't verify how display values change.
Is there a way to perform some sort of delay in such case ?

Thank in advance.


Solution

  • Not sure I understand this fully, but I think you should look more into kotlin coroutines and flows.

    Coroutines can achieve the effect you seek, and are bound really well to compose as internal support.

    I cannot answer your question fully because you didn't show any snippet of code to work on, but with coroutines and flows you can create a flow, wait any amount of seconds and emit a value into the flows once the waiting is done.

    Flows can be listened to in Compose by using the collectAsState method.