-
Notifications
You must be signed in to change notification settings - Fork 0
Async Testing β Testing normal functions that launch a coroutine
Devrath edited this page Oct 25, 2023
·
8 revisions

- Most of the time we come across scenarios where the system under test(
SUT) is a normal function. - But this normal function launches a new co-routine and performs some action in an
asyncway. - If the function was a
suspendfunction, We could have used arun-blockingway to test it on the test case so the test case does not finish until the suspend function finishes the execution. - This is more common where a
viewcalls a function in aview-modeland theview-modellaunches a co-routine. - Since the launched co-routine is independent we will not be able to use a run-blocking function.
ERROR OBSERVED:-> Module with the Main dispatcher had failed to initialize. For tests Dispatchers.setMain from kotlinx-coroutines-test module can be used
ERROR OBSERVED:-> The coroutines are to be run on main-dispatcher, But the point to note here is that the main-dispatcher is associated with main-thread-looper, The main thread is associated with an android device and the this is not available when unit tests are run , So we face this error