Skip to content

Commit

Permalink
Merge pull request #70 from rubensousa/rule-fix
Browse files Browse the repository at this point in the history
Fix retry rule in default case
  • Loading branch information
rubensousa authored Sep 30, 2024
2 parents 54696d6 + 843e97e commit 30e915c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions docs/changelog/junit4-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/junit4-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 30e915c

Please sign in to comment.