반응형
enabled
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
import org.apache.commons.lang3.SystemUtils
class MyTests : StringSpec({
"strings.length should return size of string - disabled".config(enabled = false) {
"hello".length shouldBe 5
}
// implementation("org.apache.commons:commons-lang3:3.12.0")
"test on windows".config(enabled = SystemUtils.IS_OS_WINDOWS) {
"hello".length shouldBe 5
}
})
enabledIf
import io.kotest.core.spec.style.StringSpec
import io.kotest.core.test.EnabledIf
class MyTests : StringSpec({
val enableSafe: EnabledIf = { it.name.testName.startsWith("safe") }
"danger Will Robinson".config(enabledIf = enableSafe) {
// test here
}
"safe Will Robinson".config(enabledIf = enableSafe) {
// test here
}
})
enabledOrReasonIf
import io.kotest.core.spec.style.StringSpec
import io.kotest.core.test.Enabled
import io.kotest.core.test.TestCase
class MyTests : StringSpec({
val enableSafe: (TestCase) -> Enabled = {
if (!it.name.testName.startsWith("safe"))
Enabled.disabled("we don't like danger!")
else
Enabled.enabled
}
"danger Will Robinson".config(enabledOrReasonIf = enableSafe) {
// test here
}
"safe Will Robinson".config(enabledOrReasonIf = enableSafe) {
// test here
}
})
focus
import io.kotest.core.spec.style.StringSpec
class MyTests : StringSpec({
"test 1" {
// this will be skipped
}
// 테스트 이름 앞에 f:를 붙이면 해당 테스트만 실행되고 나머지는 skip
"f:test 2" {
// this will be executed
}
"test 3" {
// this will be skipped
}
})
bang
import io.kotest.core.spec.style.StringSpec
class MyTests : StringSpec({
// 테스트 이름 앞에 !를 붙이면 ignore
"!test 1" {
// this will be ignored
}
"test 2" {
// this will run
}
"test 3" {
// this will run too
}
})
x method
import io.kotest.core.spec.style.DescribeSpec
class MyTests : DescribeSpec({
describe("this outer block is enabled") {
xit("this test is disabled") {
// test here
}
}
xdescribe("this block is disabled") {
it("disabled by inheritance from the parent") {
// test here
}
}
})
@Ignored
import io.kotest.core.annotation.Ignored
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
@Ignored
class MyTests : StringSpec({
"test" {
"hello".length shouldBe 5
}
})
@EnabledIf
import io.kotest.core.annotation.EnabledCondition
import io.kotest.core.annotation.EnabledIf
import io.kotest.core.spec.Spec
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
import org.apache.commons.lang3.SystemUtils
import kotlin.reflect.KClass
class LinuxOnlyCondition : EnabledCondition {
override fun enabled(kclass: KClass<out Spec>): Boolean = when {
// implementation("org.apache.commons:commons-lang3:3.12.0")
kclass.simpleName?.contains("Linux") == true -> SystemUtils.IS_OS_LINUX
else -> true // non Linux tests always run
}
}
@EnabledIf(LinuxOnlyCondition::class)
class MyTests : StringSpec({
"test" {
"hello".length shouldBe 5
}
})
반응형
'Development > Kotest' 카테고리의 다른 글
[Kotest] extensions (0) | 2023.11.04 |
---|---|
[Kotest] lifecycle hook (0) | 2023.11.04 |
[Kotest] isolation modes (0) | 2023.11.04 |
[Kotest] testing styles (0) | 2023.11.04 |
[Kotest] 기본 (0) | 2023.11.04 |