diff --git a/composeApp/src/commonTest/kotlin/UltronTestFlowTest.kt b/composeApp/src/commonTest/kotlin/UltronTestFlowTest.kt index bba2037..e66f919 100644 --- a/composeApp/src/commonTest/kotlin/UltronTestFlowTest.kt +++ b/composeApp/src/commonTest/kotlin/UltronTestFlowTest.kt @@ -8,16 +8,15 @@ import kotlin.test.assertTrue class UltronTestFlowTest : UltronTest() { companion object { var order = 0 - var beforeAllTestCounter = -1 + var beforeFirstTestCounter = 0 var commonBeforeOrder = -1 var commonAfterOrder = -1 var afterOrder = -1 - } @OptIn(ExperimentalUltronApi::class) override val beforeFirstTest = { - beforeAllTestCounter = order + beforeFirstTestCounter++ UltronLog.info("Before Class") } @@ -39,6 +38,7 @@ class UltronTestFlowTest : UltronTest() { var goOrder = -1 order++ before { + assertTrue(beforeFirstTestCounter == 1, message = "beforeFirstTest block should run before all test") beforeOrder = order order++ UltronLog.info("Before TestMethod 1") @@ -49,8 +49,6 @@ class UltronTestFlowTest : UltronTest() { }.after { afterOrder = order order++ - assertTrue(beforeAllTestCounter == 0, message = "beforeAllTests block should run before all test") - assertTrue(beforeAllTestCounter < commonBeforeOrder, message = "beforeAllTests block should run before commonBefore block") assertTrue(commonBeforeOrder < beforeOrder, message = "beforeOrder block should run after commonBefore block") assertTrue(beforeOrder < goOrder, message = "Before block should run before 'go'") assertTrue(goOrder < afterOrder, message = "After block should run after 'go'") @@ -64,14 +62,14 @@ class UltronTestFlowTest : UltronTest() { }.after { UltronLog.info("After TestMethod 2") }.go { - assertTrue(beforeAllTestCounter == 0, message = "beforeAllTests block should run only once") + assertTrue(beforeFirstTestCounter == 1, message = "beforeFirstTest block should run only once") UltronLog.info("Run TestMethod 2") } } @Test fun simpleTest() = test { - assertTrue(beforeAllTestCounter == 0, message = "beforeAllTests block should run only once") + assertTrue(beforeFirstTestCounter == 1, message = "beforeFirstTest block should run only once") UltronLog.info("UltronTest simpleTest") } } \ No newline at end of file diff --git a/composeApp/src/commonTest/kotlin/UltronTestFlowTest2.kt b/composeApp/src/commonTest/kotlin/UltronTestFlowTest2.kt index 36afd43..6a03df5 100644 --- a/composeApp/src/commonTest/kotlin/UltronTestFlowTest2.kt +++ b/composeApp/src/commonTest/kotlin/UltronTestFlowTest2.kt @@ -2,15 +2,18 @@ import com.atiurin.ultron.annotations.ExperimentalUltronApi import com.atiurin.ultron.core.test.UltronTest import com.atiurin.ultron.log.UltronLog import kotlin.test.Test +import kotlin.test.assertEquals import kotlin.test.assertTrue class UltronTestFlowTest2 : UltronTest() { - var order = 0 - var beforeAllTestCounter = 0 + companion object { + var order = 0 + var beforeFirstTestCounter = 0 + } @OptIn(ExperimentalUltronApi::class) override val beforeFirstTest = { - beforeAllTestCounter = order + beforeFirstTestCounter++ order++ UltronLog.info("Before Class") } @@ -22,6 +25,7 @@ class UltronTestFlowTest2 : UltronTest() { var goOrder = -1 order++ before { + assertEquals(1, beforeFirstTestCounter, message = "beforeFirstTest block should run before all test") beforeOrder = order order++ UltronLog.info("Before TestMethod 1") @@ -31,8 +35,6 @@ class UltronTestFlowTest2 : UltronTest() { UltronLog.info("Run TestMethod 1") }.after { afterOrder = order - assertTrue(beforeAllTestCounter == 0, message = "beforeAllTests block should run before all test") - assertTrue(beforeOrder > beforeAllTestCounter, message = "Before block should run after 'Before All'") assertTrue(beforeOrder < goOrder, message = "Before block should run before 'go'") assertTrue(goOrder < afterOrder, message = "After block should run after 'go'") } @@ -45,7 +47,7 @@ class UltronTestFlowTest2 : UltronTest() { }.after { UltronLog.info("After TestMethod 2") }.go { - assertTrue(beforeAllTestCounter == 0, message = "beforeAllTests block should run only once") + assertEquals(1, beforeFirstTestCounter, message = "beforeFirstTest block should run before all test") UltronLog.info("Run TestMethod 2") } } diff --git a/gradle.properties b/gradle.properties index c49ebe1..898b741 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,4 +14,4 @@ kotlin.mpp.enableCInteropCommonization=true GROUP=com.atiurin POM_ARTIFACT_ID=ultron -VERSION_NAME=2.5.0-alpha16 +VERSION_NAME=2.5.1 diff --git a/sample-app/src/androidTest/java/com/atiurin/sampleapp/tests/testlifecycle/UltronTestFlowTest.kt b/sample-app/src/androidTest/java/com/atiurin/sampleapp/tests/testlifecycle/UltronTestFlowTest.kt index 09c2734..7251673 100644 --- a/sample-app/src/androidTest/java/com/atiurin/sampleapp/tests/testlifecycle/UltronTestFlowTest.kt +++ b/sample-app/src/androidTest/java/com/atiurin/sampleapp/tests/testlifecycle/UltronTestFlowTest.kt @@ -8,7 +8,7 @@ import org.junit.Test class UltronTestFlowTest : BaseTest() { companion object { var order = 0 - var beforeAllTestCounter = -1 + var isBeforeFirstTestCounter = 0 var commonBeforeOrder = -1 var commonAfterOrder = -1 var afterOrder = -1 @@ -17,7 +17,7 @@ class UltronTestFlowTest : BaseTest() { @OptIn(ExperimentalUltronApi::class) override val beforeFirstTest = { - beforeAllTestCounter = order + isBeforeFirstTestCounter++ UltronLog.info("Before Class") } @@ -39,6 +39,7 @@ class UltronTestFlowTest : BaseTest() { var goOrder = -1 order++ before { + assert(isBeforeFirstTestCounter == 1, lazyMessage = { "beforeFirstTest block should run before commonBefore block" }) beforeOrder = order order++ UltronLog.info("Before TestMethod 1") @@ -49,8 +50,6 @@ class UltronTestFlowTest : BaseTest() { }.after { afterOrder = order order++ - assert(beforeAllTestCounter == 0, lazyMessage = { "beforeAllTests block should run before all test" }) - assert(beforeAllTestCounter < commonBeforeOrder, lazyMessage = { "beforeAllTests block should run before commonBefore block" }) assert(commonBeforeOrder < beforeOrder, lazyMessage = { "beforeOrder block should run after commonBefore block" }) assert(beforeOrder < goOrder, lazyMessage = { "Before block should run before 'go'" }) assert(goOrder < afterOrder, lazyMessage = { "After block should run after 'go'" }) @@ -64,14 +63,14 @@ class UltronTestFlowTest : BaseTest() { }.after { UltronLog.info("After TestMethod 2") }.go { - assert(beforeAllTestCounter == 0, lazyMessage = { "beforeAllTests block should run only once" }) + assert(isBeforeFirstTestCounter == 1, lazyMessage = { "beforeFirstTest block should run only once" }) UltronLog.info("Run TestMethod 2") } } @Test fun simpleTest() = test { - assert(beforeAllTestCounter == 0, lazyMessage = { "beforeAllTests block should run only once" }) + assert(isBeforeFirstTestCounter == 1, lazyMessage = { "beforeAllTests block should run only once" }) UltronLog.info("UltronTest simpleTest") } } \ No newline at end of file diff --git a/ultron-common/src/commonMain/kotlin/com/atiurin/ultron/core/test/UltronTest.kt b/ultron-common/src/commonMain/kotlin/com/atiurin/ultron/core/test/UltronTest.kt index 1700417..3f5f047 100644 --- a/ultron-common/src/commonMain/kotlin/com/atiurin/ultron/core/test/UltronTest.kt +++ b/ultron-common/src/commonMain/kotlin/com/atiurin/ultron/core/test/UltronTest.kt @@ -26,7 +26,7 @@ open class UltronTest( * * @throws UltronException if the test class is anonymous. */ - private val className = this::class.qualifiedName + private val className = this::class.simpleName ?: throw UltronException("Don't use anonymous class for UltronTest") /**