반응형
SpecListener
import io.kotest.core.listeners.AfterSpecListener
import io.kotest.core.listeners.BeforeSpecListener
import io.kotest.core.spec.Spec
class SpecListener : BeforeSpecListener, AfterSpecListener {
override suspend fun beforeSpec(spec: Spec) {
println("beforeSpec")
}
override suspend fun afterSpec(spec: Spec) {
println("afterSpec")
}
}
import io.kotest.core.spec.style.StringSpec
class MyTests : StringSpec({
extension(SpecListener())
"test" {
println("test")
}
})
beforeSpec
test
afterSpec
TestListener
import io.kotest.core.listeners.AfterTestListener
import io.kotest.core.listeners.BeforeTestListener
import io.kotest.core.test.TestCase
import io.kotest.core.test.TestResult
object TimerListener : BeforeTestListener, AfterTestListener {
private var started = 0L
override suspend fun beforeTest(testCase: TestCase) {
started = System.currentTimeMillis()
}
override suspend fun afterTest(testCase: TestCase, result: TestResult) {
println("Duration = ${System.currentTimeMillis() - started}ms")
}
}
import io.kotest.core.spec.style.StringSpec
class MyTests : StringSpec({
extension(TimerListener)
"test" {
println("test")
}
})
test
Duration = 19ms
반응형
'Development > Kotest' 카테고리의 다른 글
[Kotest] Testcontainers (0) | 2023.11.04 |
---|---|
[Kotest] SpringBootTest (0) | 2023.11.04 |
[Kotest] lifecycle hook (0) | 2023.11.04 |
[Kotest] isolation modes (0) | 2023.11.04 |
[Kotest] conditional evaluation (0) | 2023.11.04 |