diff --git a/carioca-junit4-rules/src/main/kotlin/com/rubensousa/carioca/junit4/rules/RetryTestRule.kt b/carioca-junit4-rules/src/main/kotlin/com/rubensousa/carioca/junit4/rules/RetryTestRule.kt index f21b3d83..3db1b1bf 100644 --- a/carioca-junit4-rules/src/main/kotlin/com/rubensousa/carioca/junit4/rules/RetryTestRule.kt +++ b/carioca-junit4-rules/src/main/kotlin/com/rubensousa/carioca/junit4/rules/RetryTestRule.kt @@ -74,12 +74,13 @@ class RetryTestRule : TestRule { return object : Statement() { override fun evaluate() { var lastError: Throwable? = null - repeat(times + 1) { + var passed = false + while (!passed && currentExecution < times + 1) { try { base.evaluate() // Clear the error, since the test now passed lastError = null - return@repeat + passed = true } catch (error: Throwable) { lastError = error } diff --git a/carioca-junit4-rules/src/test/java/com/rubensousa/carioca/junit4/rules/RetryTestRuleTest.kt b/carioca-junit4-rules/src/test/java/com/rubensousa/carioca/junit4/rules/RetryTestRuleTest.kt index 31b67b73..d28484f4 100644 --- a/carioca-junit4-rules/src/test/java/com/rubensousa/carioca/junit4/rules/RetryTestRuleTest.kt +++ b/carioca-junit4-rules/src/test/java/com/rubensousa/carioca/junit4/rules/RetryTestRuleTest.kt @@ -128,6 +128,34 @@ class RetryTestRuleFailureTest { } +@RetryTest(times = 10) +class RetryTestRuleSuccessfulTest { + + @get:Rule + val retryRule = RetryTestRule() + + @Test + fun `test is executed once because it passes`() { + assertThat(retryRule.currentExecution).isEqualTo(0) + SingletonState.iteration++ + } + + companion object { + + @BeforeClass + @JvmStatic + fun before() { + SingletonState.iteration = 0 + } + + @AfterClass + @JvmStatic + fun after() { + SingletonState.assertIterations(1) + } + } +} + class RetryTestRuleEmptyTest { @get:Rule diff --git a/docs/changelog/junit4-rules.md b/docs/changelog/junit4-rules.md index c5923c7b..d153de44 100644 --- a/docs/changelog/junit4-rules.md +++ b/docs/changelog/junit4-rules.md @@ -2,6 +2,14 @@ ## Version 1.0.0 +### 1.0.0-beta01 + +2024-10-01 + +#### Bug fixes + +- Fixed `RetryTestRule` not finishing up correctly if test passes [#70](https://github.com/rubensousa/Carioca/pull/70) + ### 1.0.0-alpha02 2024-09-30 diff --git a/docs/junit4-rules.md b/docs/junit4-rules.md index 0face4a6..d40fee4d 100644 --- a/docs/junit4-rules.md +++ b/docs/junit4-rules.md @@ -8,7 +8,7 @@ This rule can be useful for end-to-end tests that have some degree of tolerable Avoid using it for all sorts of tests! -Total executions = `max(1, 1 + times)` +Total executions = `[1, 1 + times]`, depends on which execution the test actually passes ```kotlin linenums="1" @RetryTest(times = 9) diff --git a/mkdocs.yml b/mkdocs.yml index d5891436..2abd4cf4 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -26,7 +26,7 @@ extra: report: version: '1.0.0-alpha03' junit4_rules: - version: '1.0.0-alpha02' + version: '1.0.0-beta01' allure_plugin: version: '1.0.0-alpha04' hilt: