forked from Baeldung/kotlin-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KTLN-628] Add samples (Baeldung#575)
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
kotest/src/test/kotlin/com/baeldung/kotest/junitvskotest/JUnit5SampleTest.kt
This file contains 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
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()") | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
kotest/src/test/kotlin/com/baeldung/kotest/junitvskotest/KotestSampleTest.kt
This file contains 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
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") | ||
} | ||
}) |