반응형
FunSpec
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
class MyTests : FunSpec({
test("String length should return the length of the string") {
"sammy".length shouldBe 5
"".length shouldBe 0
}
context("this outer block is enabled") {
xtest("this test is disabled") {
// test here
}
}
xcontext("this block is disabled") {
test("disabled by inheritance from the parent") {
// test here
}
}
})
FreeSpec
import io.kotest.core.spec.style.FreeSpec
import io.kotest.matchers.shouldBe
class MyTests : FreeSpec({
"String.length" - {
"should return the length of the string" {
"sammy".length shouldBe 5
"".length shouldBe 0
}
}
"containers can be nested as deep as you want" - {
"and so we nest another container" - {
"yet another container" - {
"finally a real test" {
1 + 1 shouldBe 2
}
}
}
}
})
WordSpec
import io.kotest.core.spec.style.WordSpec
import io.kotest.matchers.shouldBe
class MyTests : WordSpec({
"String.length" should {
"return the length of the string" {
"sammy".length shouldBe 5
"".length shouldBe 0
}
}
"Hello" When {
"asked for length" should {
"return 5" {
"Hello".length shouldBe 5
}
}
"appended to Bob" should {
"return Hello Bob" {
"Hello " + "Bob" shouldBe "Hello Bob"
}
}
}
})
StringSpec
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
class MyTests : StringSpec({
"strings.length should return size of string" {
"hello".length shouldBe 5
}
"strings.length should return size of string - disabled".config(enabled = false, invocations = 3) {
"hello".length shouldBe 5
}
})
ShouldSpec
class MyTests : ShouldSpec({
should("return the length of the string") {
"sammy".length shouldBe 5
"".length shouldBe 0
}
context("String.length") {
should("return the length of the string") {
"sammy".length shouldBe 5
"".length shouldBe 0
}
}
context("this outer block is enabled") {
xshould("this test is disabled") {
// test here
}
}
xcontext("this block is disabled") {
should("disabled by inheritance from the parent") {
// test here
}
}
})
ExpectSpec
import io.kotest.core.spec.style.ExpectSpec
class MyTests : ExpectSpec({
expect("my test") {
// test here
}
context("a calculator") {
expect("simple addition") {
// test here
}
expect("integer overflow") {
// test here
}
}
context("this outer block is enabled") {
xexpect("this test is disabled") {
// test here
}
}
xcontext("this block is disabled") {
expect("disabled by inheritance from the parent") {
// test here
}
}
})
AnnotationSpec
import io.kotest.core.spec.style.AnnotationSpec
import io.kotest.matchers.shouldBe
class MyTests : AnnotationSpec() {
@BeforeEach
fun beforeTest() {
println("Before each test")
}
@Test
fun test1() {
1 shouldBe 1
}
@Test
fun test2() {
3 shouldBe 3
}
}
BehaviorSpec
import io.kotest.core.spec.style.BehaviorSpec
class MyTests : BehaviorSpec({
Given("test given") {
When("test when") {
Then("test then") {
// test code
}
}
}
given("a broomstick") {
`when`("I sit on it") {
then("I should be able to fly") {
// test code
}
}
`when`("I throw it away") {
then("it should come back") {
// test code
}
}
and("a witch") {
`when`("The witch sits on it") {
and("she laughs hysterically") {
then("She should be able to fly") {
// test code
}
}
}
}
}
xgiven("this is disabled") {
When("disabled by inheritance from the parent") {
then("disabled by inheritance from its grandparent") {
// disabled test
}
}
}
given("this is active") {
When("this is active too") {
xthen("this is disabled") {
// disabled test
}
}
}
})
DescribeSpec
import io.kotest.core.spec.style.DescribeSpec
class MyTests : DescribeSpec({
describe("score") {
it("start as zero") {
// test here
}
describe("with a strike") {
it("adds ten") {
// test here
}
it("carries strike to the next frame") {
// test here
}
}
describe("for the opposite team") {
it("Should negate one score") {
// test here
}
}
}
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
}
}
})
FeatureSpec
import io.kotest.core.spec.style.FeatureSpec
class MyTests : FeatureSpec({
feature("the can of coke") {
scenario("should be fizzy when I shake it") {
// test here
}
scenario("and should be tasty") {
// test here
}
}
feature("this outer block is enabled") {
xscenario("this test is disabled") {
// test here
}
}
xfeature("this block is disabled") {
scenario("disabled by inheritance from the parent") {
// test here
}
}
})
반응형
'Development > Kotest' 카테고리의 다른 글
[Kotest] extensions (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 |
[Kotest] 기본 (0) | 2023.11.04 |