Last active
January 12, 2022 00:30
-
-
Save yukihane/62f3a708300b5a2798c3563e83bf8eac to your computer and use it in GitHub Desktop.
Kotest の data driven testing, forAll と withData の違い
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.kotest.core.spec.style.FunSpec | |
import io.kotest.data.forAll | |
import io.kotest.data.row | |
import io.kotest.datatest.withData | |
class SampleTest : FunSpec({ | |
beforeAny { println("before any") } | |
beforeContainer { println("before container") } | |
beforeEach { println("before each") } | |
beforeSpec { println("before spec") } | |
beforeTest { println("before test") } | |
afterAny { println("after any") } | |
afterContainer { println("after container") } | |
afterEach { println("after each") } | |
afterSpec { println("after spec") } | |
afterTest { println("after test") } | |
finalizeSpec { println("finalize spec") } | |
// https://kotest.io/docs/framework/datatesting/data_driven_testing_4.2.0 | |
context("forAll で行うテスト") { | |
forAll(row(1), row(2), row(3)) { i: Int -> println("testing forAll $i") } | |
} | |
// https://kotest.io/docs/framework/datatesting/data-driven-testing.html | |
context("withData で行うテスト") { | |
withData(1, 2, 3) { i -> println("testing withData $i") } | |
} | |
// https://kotest.io/docs/framework/datatesting/data_driven_testing_4.2.0 の最下部 | |
context("withData を使わずテストを分ける") { | |
listOf(row("test1", 1), row("test2", 2), row("test3", 3)).map { (name, num) -> | |
test(name) { | |
println("$name $num") | |
} | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment