Skip to content

Commit

Permalink
[KTLN-628] Add samples (Baeldung#575)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoColman authored Sep 16, 2023
1 parent b5838a8 commit f3daa3f
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.baeldung.kotest.junitvskotest

import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.TestInstance.Lifecycle

@TestInstance(Lifecycle.PER_CLASS)
class JUnit5SampleTest {
@BeforeAll
fun setUpClass() {
println("Setting up test class")
}

@BeforeEach
fun setUp() {
println("Setting up test")
}

@AfterEach
fun tearDown() {
println("Tearing down test")
}

@AfterAll
fun tearDownClass() {
println("Tearing down test class")
}

@Test
fun testExample() {
val result = 2 + 2

assertEquals (4, result, "2 + 2 should be equal to 4")
assertTrue(result > 0, "Result should be positive")
assertFalse(result < 0, "Result should not be negative")
assertNotNull(result, "Result should not be null")

println("Executing testExample()")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.baeldung.kotest.junitvskotest

import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.ints.shouldBeGreaterThan
import io.kotest.matchers.ints.shouldNotBeLessThan
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe

class KotestSampleTest : FunSpec({
beforeSpec {
println("Setting up test class")
}

afterSpec {
println("Tearing down test class")
}

beforeEach {
println("Setting up test")
}

afterEach {
println("Tearing down test")
}

// This is a test
test("Test Example") {
val result = 2 + 2

result shouldBe 4
result shouldBeGreaterThan 0
result shouldNotBeLessThan 0
result shouldNotBe null

println("Executing Test Example")
}
})

0 comments on commit f3daa3f

Please sign in to comment.