Includes a JUnit 5 Extension that can dump coroutines on timeout. Like CoroutinesTimeout JUnit 4 rule, but built for JUnit 5 and with almost 100% test coverage (yes, I test code that's meant to test others' code).
Requires Java 8 or later. Verified working with the latest JUnit 5 version, which you can find in the gradle.properties.
You can find the latest version on Bintray.
It is also on Maven Central and jcenter.
The simplest way to get started:
@CoroutinesTimeout(timeout = "PT1S")
class TimeConsumingTest {
@CoroutinesTimeout(timeout = "PT2S")
@Test
fun testOverrideTimeout() {
runBlocking { delay(1500) }
}
@Test
fun test() {
runBlocking { delay(800) }
}
}
See KDoc for more details.
Sample coroutines dump:
Coroutines dump 2020/08/14 16:21:18
Coroutine "coroutine#1":BlockingCoroutine{Active}@78383390, state: SUSPENDED
at com.asarkar.kotlinx.test.ClassLevelTimeout$testTimeout$1.invokeSuspend(ClassLevelTimeout.kt:16)
(Coroutine creation stacktrace)
...
at com.asarkar.kotlinx.test.ClassLevelTimeout.testTimeout(ClassLevelTimeout.kt:16)
...
at com.asarkar.kotlinx.test.CoroutinesTimeoutExtension$interceptTestMethod$testResult$1.call(CoroutinesTimeoutExtension.kt:30)
...
at java.base/java.lang.Thread.run(Thread.java:834)
This project is a volunteer effort. You are welcome to send pull requests, ask questions, or create issues. If you like it, you can help by spreading the word!
Copyright 2020 Abhijit Sarkar - Released under Apache License v2.0.