File tree 5 files changed +57
-3
lines changed
kotlinx-coroutines-core-test
5 files changed +57
-3
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,8 @@ GlobalScope.launch {
31
31
* [ core] ( core/README.md ) &mdash ; Kotlin/JVM implementation of common coroutines with additional features:
32
32
* ` Dispatchers.IO ` dispatcher for blocking coroutines;
33
33
* ` Executor.asCoroutineDispatcher() ` extension, custom thread pools, and more.
34
+ * [ core-test] ( core/README.md ) &mdash ; test utilities for coroutines, currently with one feature:
35
+ * ` MainDispatcherInjector.inject() ` to override ` Dispatchers.Main ` in tests.
34
36
* [ js] ( js/README.md ) &mdash ; Kotlin/JS implementation of common coroutines with ` Promise ` support.
35
37
* [ native] ( native/README.md ) &mdash ; Kotlin/Native implementation of common coroutines with ` runBlocking ` single-threaded event loop.
36
38
* [ reactive] ( reactive/README.md ) &mdash ; modules that provide builders and iteration support for various reactive streams libraries:
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ To release new `<version>` of `kotlinx-coroutines`:
12
12
` git merge origin/master `
13
13
14
14
4 . Search & replace ` <old-version> ` with ` <version> ` across the project files. Should replace in:
15
- * [ ` README.md ` ] ( README.md )
15
+ * [ ` README.md ` ] ( README.md ) (native, core, core-test modules)
16
16
* [ ` coroutines-guide.md ` ] ( docs/coroutines-guide.md )
17
17
* [ ` gradle.properties ` ] ( gradle.properties )
18
18
* [ ` ui/kotlinx-coroutines-android/example-app/gradle.properties ` ] ( ui/kotlinx-coroutines-android/example-app/gradle.properties )
Original file line number Diff line number Diff line change @@ -5,5 +5,6 @@ Module name below corresponds to the artifact name in Maven/Gradle.
5
5
6
6
## Modules
7
7
8
- * [ kotlinx-coroutines-core] ( kotlinx-coroutines-core/README.md ) -- core coroutine builders and synchronization primitives.
8
+ * [ kotlinx-coroutines-core] ( kotlinx-coroutines-core/README.md ) &mdash ; core coroutine builders and synchronization primitives.
9
+ * [ kotlinx-coroutines-core-test] ( kotlinx-coroutines-core-test/README.md ) &mdash ; coroutines test utilities such as Main dispatcher injection.
9
10
Original file line number Diff line number Diff line change
1
+ # Module kotlinx-coroutines-core-test
2
+
3
+ Test utilities for ` kotlinx.coroutines ` . Provides ` MainDispatcherInjector.inject ` to override ` Main ` dispatcher.
4
+
5
+ ## Using in your project
6
+
7
+ Add ` kotlinx-coroutines-core-test ` to your project test dependencies:
8
+ ```
9
+ dependencies {
10
+ testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-test:1.0.0-RC1'
11
+ }
12
+ ```
13
+
14
+ ** Do not** depend on this project in your main sources, all utilities are intended and designed to be used only from tests.
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] will injectable implementation, which uses ` Dispatchers.Unconfined ` default.
18
+
19
+ You can override this implementation using [ inject] [ MainDispatcherInjector.inject ] method with any [ CoroutineDispatcher] implementation, e.g.:
20
+
21
+ ``` kotlin
22
+
23
+ class SomeTest {
24
+
25
+ private val mainThreadSurrogate = newSingleThreadContext(" UI thread" )
26
+
27
+ @Before
28
+ fun setUp () {
29
+ MainDispatcherInjector .inject(mainThreadSurrogate)
30
+ }
31
+
32
+ @After
33
+ fun tearDown () {
34
+ MainDispatcherInjector .reset() // reset main dispatcher to Unconfined
35
+ mainThreadSurrogate.close()
36
+ }
37
+
38
+ @Test
39
+ fun testSomeUI () = runBlocking {
40
+ launch(Dispatchers .Main ) {
41
+ .. .
42
+ }
43
+ }
44
+ }
45
+ ```
46
+
47
+ <!-- - MODULE kotlinx-coroutines-core -->
48
+ <!-- - INDEX kotlinx.coroutines -->
49
+ [ Dispatchers.Main ] : https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-main.html
50
+ [ CoroutineDispatcher ] : https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html
51
+ <!-- - END -->
Original file line number Diff line number Diff line change 4
4
5
5
site.root =https://kotlin.github.io/kotlinx.coroutines
6
6
7
- module.roots =common js core integration native reactive ui
7
+ module.roots =common js core core-test integration native reactive ui
8
8
module.marker =build.gradle
9
9
module.docs =build/dokka
You can’t perform that action at this time.
0 commit comments