In a TestCaseExtension
, I want to log test-specific information. At first sight, doing it like this seems to work:
import io.kotlintest.*
import io.kotlintest.extensions.SpecLevelExtension
import io.kotlintest.extensions.TestCaseExtension
import io.kotlintest.specs.DescribeSpec
class MySpec : DescribeSpec({
describe("bar") {
it("a") {}
it("b") {}
}
}) {
override fun extensions(): List<SpecLevelExtension> = listOf(MyExtension())
}
class MyExtension : TestCaseExtension {
override suspend fun intercept(
testCase: TestCase,
execute: suspend (TestCase, suspend (TestResult) -> Unit) -> Unit,
complete: suspend (TestResult) -> Unit
) {
execute(testCase) { testResult ->
if (testCase.type == TestType.Test) {
println(testCase.description.name)
}
complete(testResult)
}
}
}
In IntelliJ IDEA, the output for the first test is "Scenario: a" and the output for the second test is "Scenario: b". However, when changing describe("bar")
to describe("foo")
, the output for the first test becomes "Scenario: a[newline]Scenario: b", while the output for the second test becomes empty.
So, how can I properly assign logged information to each test? Maybe using println
is not even the right choice?
- io.kotlintest:kotlintest-runner-junit5:3.2.1
- JDK 10.0.2
- IntelliJ IDEA 2018.3.2 (Community Edition)