rook
05/24/2021, 1:54 PMDispatcher
is provided during testing?streetsofboston
05/24/2021, 2:04 PMlaunch
it on the CoroutineScope that is or is a child of your runBlocking's or runBlockingTest's CoroutineScope, your test won't finish until all you asynchronous code has finished (with good result or an exception).
However, if you have delays, timeouts, etc and you don't want to have long running tests, or when you launch async code from different CoroutineScopes, then using runBlockingTest with its TestCoroutineDispatcher is of great use, since you can fast-forward through time.streetsofboston
05/24/2021, 2:05 PMJavier
05/24/2021, 2:05 PMrunBlockingTest
being not multiplatform and so buggy... I think there is no way to testing properly without injecting it 😕Javier
05/24/2021, 2:06 PMstreetsofboston
05/24/2021, 2:06 PMJavier
05/24/2021, 2:07 PMstreetsofboston
05/24/2021, 2:07 PMJavier
05/24/2021, 2:07 PMJavier
05/24/2021, 2:08 PMstreetsofboston
05/24/2021, 2:08 PMstreetsofboston
05/24/2021, 2:09 PMJavier
05/24/2021, 2:09 PMJavier
05/24/2021, 2:09 PMrook
05/24/2021, 2:12 PMcustomScope.launch(<http://Dispatchers.IO|Dispatchers.IO>)
rook
05/24/2021, 2:18 PMrunBlockingTest
in my test, however the launch block appears to not have time to complete before I try to verify the results.rook
05/24/2021, 2:19 PMrunBlockingTest
would actually await completion of the block, but it seems that because the scope is custom, I won’t be able to rely on thatrook
05/24/2021, 2:20 PMmkrussel
05/24/2021, 3:52 PMrunBlockingTest
so that the launch has finished before you do your asserting.
Even though most samples show fun test() = runBlocking
, you can place the runBlocking
inside the body of a normal test method.