Skip to content

Commit fd8810a

Browse files
authored
Improve docs for the test module (#3074)
Fixes #3067 Fixes #3061
1 parent dc0e9d6 commit fd8810a

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

kotlinx-coroutines-test/common/src/TestScope.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public fun TestScope.runCurrent(): Unit = testScheduler.runCurrent()
7575
* Moves the virtual clock of this dispatcher forward by [the specified amount][delayTimeMillis], running the
7676
* scheduled tasks in the meantime.
7777
*
78-
* In contrast with [TestScope.advanceTimeBy], this function does not run the tasks scheduled at the moment
78+
* In contrast with `TestCoroutineScope.advanceTimeBy`, this function does not run the tasks scheduled at the moment
7979
* [currentTime] + [delayTimeMillis].
8080
*
8181
* @throws IllegalStateException if passed a negative [delay][delayTimeMillis].

kotlinx-coroutines-test/jvm/src/migration/DelayController.kt

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import kotlinx.coroutines.*
1111
* Control the virtual clock time of a [CoroutineDispatcher].
1212
*
1313
* Testing libraries may expose this interface to the tests instead of [TestCoroutineDispatcher].
14+
*
15+
* This interface is deprecated without replacement.
16+
* Instead, [TestCoroutineScheduler] is supposed to be used to control the virtual time.
17+
* Please see the
18+
* [migration guide](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-test/MIGRATION.md)
19+
* for an instruction on how to update the code for the new API.
1420
*/
1521
@ExperimentalCoroutinesApi
1622
@Deprecated(

kotlinx-coroutines-test/jvm/src/migration/TestBuildersDeprecated.kt

+26-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import kotlin.jvm.*
1414
/**
1515
* Executes a [testBody] inside an immediate execution dispatcher.
1616
*
17+
* This method is deprecated in favor of [runTest]. Please see the
18+
* [migration guide](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-test/MIGRATION.md)
19+
* for an instruction on how to update the code for the new API.
20+
*
1721
* This is similar to [runBlocking] but it will immediately progress past delays and into [launch] and [async] blocks.
1822
* You can use this to write tests that execute in the presence of calls to [delay] without causing your test to take
1923
* extra time.
@@ -45,7 +49,10 @@ import kotlin.jvm.*
4549
* then they must implement [DelayController] and [TestCoroutineExceptionHandler] respectively.
4650
* @param testBody The code of the unit-test.
4751
*/
48-
@Deprecated("Use `runTest` instead to support completing from other dispatchers.", level = DeprecationLevel.WARNING)
52+
@Deprecated("Use `runTest` instead to support completing from other dispatchers. " +
53+
"Please see the migration guide for details: " +
54+
"https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-test/MIGRATION.md",
55+
level = DeprecationLevel.WARNING)
4956
// Since 1.6.0, ERROR in 1.7.0 and removed as experimental in 1.8.0
5057
public fun runBlockingTest(
5158
context: CoroutineContext = EmptyCoroutineContext,
@@ -101,8 +108,16 @@ public fun runBlockingTestOnTestScope(
101108

102109
/**
103110
* Convenience method for calling [runBlockingTest] on an existing [TestCoroutineScope].
111+
*
112+
* This method is deprecated in favor of [runTest], whereas [TestCoroutineScope] is deprecated in favor of [TestScope].
113+
* Please see the
114+
* [migration guide](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-test/MIGRATION.md)
115+
* for an instruction on how to update the code for the new API.
104116
*/
105-
@Deprecated("Use `runTest` instead to support completing from other dispatchers.", level = DeprecationLevel.WARNING)
117+
@Deprecated("Use `runTest` instead to support completing from other dispatchers. " +
118+
"Please see the migration guide for details: " +
119+
"https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-test/MIGRATION.md",
120+
level = DeprecationLevel.WARNING)
106121
// Since 1.6.0, ERROR in 1.7.0 and removed as experimental in 1.8.0
107122
public fun TestCoroutineScope.runBlockingTest(block: suspend TestCoroutineScope.() -> Unit): Unit =
108123
runBlockingTest(coroutineContext, block)
@@ -117,8 +132,16 @@ public fun TestScope.runBlockingTest(block: suspend TestScope.() -> Unit): Unit
117132

118133
/**
119134
* Convenience method for calling [runBlockingTest] on an existing [TestCoroutineDispatcher].
135+
*
136+
* This method is deprecated in favor of [runTest], whereas [TestCoroutineScope] is deprecated in favor of [TestScope].
137+
* Please see the
138+
* [migration guide](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-test/MIGRATION.md)
139+
* for an instruction on how to update the code for the new API.
120140
*/
121-
@Deprecated("Use `runTest` instead to support completing from other dispatchers.", level = DeprecationLevel.WARNING)
141+
@Deprecated("Use `runTest` instead to support completing from other dispatchers. " +
142+
"Please see the migration guide for details: " +
143+
"https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-test/MIGRATION.md",
144+
level = DeprecationLevel.WARNING)
122145
// Since 1.6.0, ERROR in 1.7.0 and removed as experimental in 1.8.0
123146
public fun TestCoroutineDispatcher.runBlockingTest(block: suspend TestCoroutineScope.() -> Unit): Unit =
124147
runBlockingTest(this, block)

kotlinx-coroutines-test/jvm/src/migration/TestCoroutineScope.kt

+14-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,17 @@ import kotlin.coroutines.*
1111

1212
/**
1313
* A scope which provides detailed control over the execution of coroutines for tests.
14+
*
15+
* This scope is deprecated in favor of [TestScope].
16+
* Please see the
17+
* [migration guide](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-test/MIGRATION.md)
18+
* for an instruction on how to update the code for the new API.
1419
*/
1520
@ExperimentalCoroutinesApi
16-
@Deprecated("Use `TestScope` in combination with `runTest` instead")
21+
@Deprecated("Use `TestScope` in combination with `runTest` instead." +
22+
"Please see the migration guide for details: " +
23+
"https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-test/MIGRATION.md",
24+
level = DeprecationLevel.WARNING)
1725
// Since 1.6.0, ERROR in 1.7.0 and removed as experimental in 1.8.0
1826
public interface TestCoroutineScope : CoroutineScope {
1927
/**
@@ -139,6 +147,11 @@ public fun TestCoroutineScope(context: CoroutineContext = EmptyCoroutineContext)
139147
/**
140148
* A coroutine scope for launching test coroutines.
141149
*
150+
* This is a function for aiding in migration from [TestCoroutineScope] to [TestScope].
151+
* Please see the
152+
* [migration guide](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-test/MIGRATION.md)
153+
* for an instruction on how to update the code for the new API.
154+
*
142155
* It ensures that all the test module machinery is properly initialized.
143156
* * If [context] doesn't define a [TestCoroutineScheduler] for orchestrating the virtual time used for delay-skipping,
144157
* a new one is created, unless either

0 commit comments

Comments
 (0)