Here is an always failing data-driven spock test:
class HelloSpockSpec extends Specification {
def "test"() {
expect:
1 == number
where:
number << [2, 3]
}
}
When this test is ran from maven, as expected, it executes 2 times, all 2 times it fails and then it fails the build:
mvn test
...
[ERROR] Failures:
[ERROR] HelloSpockSpec.test(Object)
[ERROR] Run 1: HelloSpockSpec.test:23 Condition not satisfied:
1 == a
| |
| 2
false
[ERROR] Run 2: HelloSpockSpec.test:23 Condition not satisfied:
1 == a
| |
| 3
false
[INFO] Run 3: PASS
[INFO]
[INFO]
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
So far so good, except the [INFO] Run 3: PASS
line looks suspicious, as there should be only 2 runs.
When the same test is executed with surefire's rerunFailingTestsCount
option:
mvn test -Dsurefire.rerunFailingTestsCount=1
[WARNING] Flakes:
[WARNING] HelloSpockSpec.test(Object)
[ERROR] Run 1: HelloSpockSpec.test:23 Condition not satisfied:
1 == a
| |
| 2
false
[ERROR] Run 2: HelloSpockSpec.test:23 Condition not satisfied:
1 == a
| |
| 3
false
[INFO] Run 3: PASS
[ERROR] Run 4: HelloSpockSpec.test:23 Condition not satisfied:
1 == a
| |
| 2
false
[ERROR] Run 5: HelloSpockSpec.test:23 Condition not satisfied:
1 == a
| |
| 3
false
[INFO] Run 6: PASS
[INFO]
[INFO]
[WARNING] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Flakes: 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
something strange happens:
- Build is successful, however there is a test which always fails;
- This test is marked as flaky, meaning it failed and then passed, but again, this test should always fail;
- The number of Runs is 6, but it should be 4 (2 runs because of
where
block, multiplied by the number of reruns+1).
The problem seems to come from the Run N: PASS
line, it seems that surefire thinks that the test was successful and marks it as flaky.
This issue looks very concerning - combination of data-driven tests and surefire's rerunFailingTestsCount option means that tests might be marked as flaky (even though they always failing), and due to fact that surefire does not fail the maven build, might be unnoticed.
Or am I missing something here?
Here is a github project, check out the build logs