@@ -39,7 +39,7 @@ public expect class TestResult
39
39
* Executes [testBody] as a test in a new coroutine, returning [TestResult].
40
40
*
41
41
* On JVM and Native, this function behaves similarly to `runBlocking`, with the difference that the code that it runs
42
- * will skip delays. This allows to use [delay] in without causing the tests to take more time than necessary.
42
+ * will skip delays. This allows to use [delay] in tests without causing them to take more time than necessary.
43
43
* On JS, this function creates a `Promise` that executes the test body with the delay-skipping behavior.
44
44
*
45
45
* ```
@@ -60,7 +60,7 @@ public expect class TestResult
60
60
* immediately return the produced [TestResult] from the test method, without doing anything else afterwards. See
61
61
* [TestResult] for details on this.
62
62
*
63
- * The test is run in a single thread, unless other [CoroutineDispatcher] are used for child coroutines.
63
+ * The test is run on a single thread, unless other [CoroutineDispatcher] are used for child coroutines.
64
64
* Because of this, child coroutines are not executed in parallel to the test body.
65
65
* In order for the spawned-off asynchronous code to actually be executed, one must either [yield] or suspend the
66
66
* test body some other way, or use commands that control scheduling (see [TestCoroutineScheduler]).
@@ -84,19 +84,19 @@ public expect class TestResult
84
84
* // 3
85
85
* }
86
86
* // 2
87
- * advanceUntilIdle() // runs the tasks until their queue is empty
87
+ * testScheduler. advanceUntilIdle() // runs the tasks until their queue is empty
88
88
* // 4
89
89
* }
90
90
* ```
91
91
*
92
92
* ### Task scheduling
93
93
*
94
- * Delay- skipping is achieved by using virtual time.
94
+ * Delay skipping is achieved by using virtual time.
95
95
* If [Dispatchers.Main] is set to a [TestDispatcher] via [Dispatchers.setMain] before the test,
96
96
* then its [TestCoroutineScheduler] is used;
97
97
* otherwise, a new one is automatically created (or taken from [context] in some way) and can be used to control
98
98
* the virtual time, advancing it, running the tasks scheduled at a specific time etc.
99
- * Some convenience methods are available on [TestScope] to control the scheduler .
99
+ * The scheduler can be accessed via [TestScope.testScheduler] .
100
100
*
101
101
* Delays in code that runs inside dispatchers that don't use a [TestCoroutineScheduler] don't get skipped:
102
102
* ```
@@ -126,25 +126,27 @@ public expect class TestResult
126
126
* There's a built-in timeout of 10 seconds for the test body. If the test body doesn't complete within this time,
127
127
* then the test fails with an [AssertionError]. The timeout can be changed by setting the [timeout] parameter.
128
128
*
129
- * The test finishes by the timeout procedure cancelling the test body . If the code inside the test body does not
130
- * respond to cancellation, we will not be able to make the test execution stop, in which case, the test will hang
131
- * despite our best efforts to terminate it.
129
+ * On timeout, the test body is cancelled so that the test finishes . If the code inside the test body does not
130
+ * respond to cancellation, the timeout will not be able to make the test execution stop.
131
+ * In that case, the test will hang despite the attempt to terminate it.
132
132
*
133
133
* On the JVM, if `DebugProbes` from the `kotlinx-coroutines-debug` module are installed, the current dump of the
134
- * coroutines' stack is printed to the console on timeout.
134
+ * coroutines' stack is printed to the console on timeout before the test body is cancelled .
135
135
*
136
136
* #### Reported exceptions
137
137
*
138
138
* Unhandled exceptions will be thrown at the end of the test.
139
- * If the uncaught exceptions happen after the test finishes, the error is propagated in a platform-specific manner.
139
+ * If uncaught exceptions happen after the test finishes, they are propagated in a platform-specific manner:
140
+ * see [handleCoroutineException] for details.
140
141
* If the test coroutine completes with an exception, the unhandled exceptions are suppressed by it.
141
142
*
142
143
* #### Uncompleted coroutines
143
144
*
144
- * This method requires that, after the test coroutine has completed, all the other coroutines launched inside
145
- * [testBody] also complete, or are cancelled.
146
- * Otherwise, the test will be failed (which, on JVM and Native, means that [runTest] itself will throw
147
- * [AssertionError], whereas on JS, the `Promise` will fail with it).
145
+ * Otherwise, the test will hang until all the coroutines launched inside [testBody] complete.
146
+ * This may be an issue when there are some coroutines that are not supposed to complete, like infinite loops that
147
+ * perform some background work and are supposed to outlive the test.
148
+ * In that case, [TestScope.backgroundScope] can be used to launch such coroutines.
149
+ * They will be cancelled automatically when the test finishes.
148
150
*
149
151
* ### Configuration
150
152
*
0 commit comments