kotlinx.coroutines: Add a a way to disable automatic delay skipping with runBlockingTest
In 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.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (6 by maintainers)
Let’s say I have simple method like that:
Then I want to properly test this:
At the moment this test would fail since
runBlockingTestskips all delays automatically, which means thatstopAnimationcall would be made immediatelly, before test can check whether animation is running.