Add a a way to disable automatic delay skipping with runBlockingTest
See original GitHub issueIn many cases it would be useful to accurately control time within tests (for example when testing time-based coroutine logic). However, at the moment runBlockingTest
seems to enforce delay-skipping behavior.
There does not seem to be a good alternative to this method at the moment if I don’t want delay skipping. I can manually create TestCoroutineScope
but that takes some boilerplate and does not bring all the benefits of runBlockingTest
(such as making sure all launched tasks have been properly stopped).
At the moment I’m using copy paste version of runBlockingTest
with dispatcher.advanceUntilIdle()
removed, but that is really bad solution.
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (7 by maintainers)
Top Results From Across the Web
Unit testing a Kotlin coroutine with delay - Stack Overflow
It allows tests to use the runTest() method and TestScope to test suspending code, automatically skipping delays.
Read more >Testing Kotlin coroutines on Android
Wrapping your test's code in runTest will work for testing basic suspending functions, and it will automatically skip any delays in coroutines, making...
Read more >kotlinx-coroutines-test
The calls to delay are automatically skipped, preserving the relative execution order of the tasks. This way, it's possible to make tests finish ......
Read more >Testing Android Coroutines using runTest - craigrussell
This class adds a lot of numbers to a list, and sorts and shuffles them ... it claims to do in the docs:...
Read more >Unit Testing with Kotlin Coroutines: The Android Way - Medium
That's because the runBlocking() function can't skip the delay operation. runBlockingTest(). runBlockingTest() is a part of the kotlinx.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Let’s say I have simple method like that:
Then I want to properly test this:
At the moment this test would fail since
runBlockingTest
skips all delays automatically, which means thatstopAnimation
call would be made immediatelly, before test can check whether animation is running.You are correct. Closing this as duplicate.