1
1
# Module kotlinx-coroutines-test
2
2
3
- Test utilities for ` kotlinx.coroutines ` . Provides ` Dispatchers.setMain ` to override ` Main ` dispatcher.
3
+ Test utilities for ` kotlinx.coroutines ` . Provides ` Dispatchers.setMain ` to override the ` Main ` dispatcher.
4
4
5
5
## Using in your project
6
6
@@ -13,10 +13,10 @@ dependencies {
13
13
14
14
** Do not** depend on this project in your main sources, all utilities are intended and designed to be used only from tests.
15
15
16
- Once you have it in runtime, [ ` ServiceLoader ` ] ( https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html ) mechanism will
17
- overwrite [ Dispatchers.Main] with testable implementation.
16
+ Once you have this dependency in the runtime, [ ` ServiceLoader ` ] ( https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html ) mechanism will
17
+ overwrite [ Dispatchers.Main] with a testable implementation.
18
18
19
- You can override this implementation using [ setMain] [ Dispatchers. setMain] method with any [ CoroutineDispatcher] implementation, e.g.:
19
+ You can override the ` Main ` implementation using [ setMain] [ setMain ] method with any [ CoroutineDispatcher] implementation, e.g.:
20
20
21
21
``` kotlin
22
22
@@ -31,13 +31,13 @@ class SomeTest {
31
31
32
32
@After
33
33
fun tearDown () {
34
- Dispatchers .resetMain() // reset main dispatcher to original Main dispatcher
34
+ Dispatchers .resetMain() // reset main dispatcher to the original Main dispatcher
35
35
mainThreadSurrogate.close()
36
36
}
37
37
38
38
@Test
39
39
fun testSomeUI () = runBlocking {
40
- launch(Dispatchers .Main ) { // Will be launched in mainThreadSurrogate dispatcher
40
+ launch(Dispatchers .Main ) { // Will be launched in the mainThreadSurrogate dispatcher
41
41
.. .
42
42
}
43
43
}
@@ -48,4 +48,7 @@ class SomeTest {
48
48
<!-- - INDEX kotlinx.coroutines -->
49
49
[ Dispatchers.Main ] : https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-main.html
50
50
[ CoroutineDispatcher ] : https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html
51
+ <!-- - MODULE kotlinx-coroutines-test -->
52
+ <!-- - INDEX kotlinx.coroutines.test -->
53
+ [ setMain ] : https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-test/kotlinx.coroutines.test/kotlinx.coroutines.-dispatchers/set-main.html
51
54
<!-- - END -->
0 commit comments