From f3daa3fd66b6c55ba022721f9659205a039bdf2f Mon Sep 17 00:00:00 2001 From: Leonardo Colman Lopes Date: Sat, 16 Sep 2023 01:56:27 -0300 Subject: [PATCH] [KTLN-628] Add samples (#575) --- .../kotest/junitvskotest/JUnit5SampleTest.kt | 48 +++++++++++++++++++ .../kotest/junitvskotest/KotestSampleTest.kt | 37 ++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 kotest/src/test/kotlin/com/baeldung/kotest/junitvskotest/JUnit5SampleTest.kt create mode 100644 kotest/src/test/kotlin/com/baeldung/kotest/junitvskotest/KotestSampleTest.kt diff --git a/kotest/src/test/kotlin/com/baeldung/kotest/junitvskotest/JUnit5SampleTest.kt b/kotest/src/test/kotlin/com/baeldung/kotest/junitvskotest/JUnit5SampleTest.kt new file mode 100644 index 000000000..2e59ce4a4 --- /dev/null +++ b/kotest/src/test/kotlin/com/baeldung/kotest/junitvskotest/JUnit5SampleTest.kt @@ -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()") + } +} diff --git a/kotest/src/test/kotlin/com/baeldung/kotest/junitvskotest/KotestSampleTest.kt b/kotest/src/test/kotlin/com/baeldung/kotest/junitvskotest/KotestSampleTest.kt new file mode 100644 index 000000000..65e11b65f --- /dev/null +++ b/kotest/src/test/kotlin/com/baeldung/kotest/junitvskotest/KotestSampleTest.kt @@ -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") + } +}) \ No newline at end of file