U75957
06/09/2019, 4:36 PM@beforeTest
and async @afterTest
will be properly chained. But in fact @beforeTest
, @afterTest
and an actual test starts in parallel. How to achieve the expected result?
class TestA : CoroutineScope by GlobalScope {
@BeforeTest
fun beforeTest() = promise {
println("beforeTest START")
delay(100)
println("beforeTest END")
}
@AfterTest
fun afterTest() = promise {
println("afterTest START")
delay(100)
println("afterTest END")
}
@Test
fun test1() = promise {
println("test1 START")
delay(100)
assertTrue(true)
println("test1 END")
}
@Test
fun test2() = promise {
println("test2 START")
delay(100)
assertTrue(true)
println("test2 END")
}
}
result:
JS: beforeTest START
JS: test1 START
JS: afterTest START
JS: beforeTest END
JS: test1 END
JS: afterTest END
JS: beforeTest START
JS: test2 START
JS: afterTest START
JS: beforeTest END
JS: test2 END
JS: afterTest END
[JB] Shagen
06/09/2019, 9:19 PMU75957
06/10/2019, 8:10 AMJS: beforeTest START
JS: beforeTest END
JS: test1 START
JS: test1 END
JS: afterTest START
JS: afterTest END
JS: beforeTest START
JS: beforeTest END
JS: test2 START
JS: test2 END
JS: afterTest START
JS: afterTest END
uli
06/10/2019, 1:48 PMpromise
from the definitions?U75957
06/10/2019, 2:23 PMdelay(100)
in promise
blockuli
06/10/2019, 2:25 PMuli
06/10/2019, 2:28 PMU75957
06/10/2019, 2:30 PMuli
06/10/2019, 2:35 PMuli
06/10/2019, 2:36 PMuli
06/10/2019, 2:37 PMU75957
06/10/2019, 2:37 PMrunBlocking
in kotlin/jsuli
06/10/2019, 2:40 PMU75957
06/10/2019, 3:02 PMkotlinx-coroutines-test
is experimental. Looks like it was released in 1.3.0-M1
4 day ago. I will try, thank you.U75957
06/10/2019, 3:46 PMkotlinx-coroutines-test
available for kotlin/js (I specify it in dependencies, but can't access it)? Or can it be resolved without kotlinx-coroutines-test
?uli
06/11/2019, 8:35 PMandylamax
07/13/2021, 11:27 PMRob Murdock
07/14/2021, 1:28 PMandylamax
07/16/2021, 2:25 AMJoffrey
09/10/2021, 8:06 AMkotlinx-coroutines-test
is still a JVM-only library, I have asked a while ago if JetBrains could release a multiplatform version of it, it's got some traction now, but still not done:
https://github.com/Kotlin/kotlinx.coroutines/issues/1996
It should come in 1.6. In the meantime, using promises to run async test doesn't seem to work properly as mentioned above.
My current workaround is to put the cleanup in a finally
block inside the promise of the test methods instead of in an @AfterTest
method.