apache / apache/maven-surefire

[SUREFIRE-1470] Unexpected report result when using rerunFailingTestsCount with groups filter in Surefire

Open
#2,100 13 comments 0 reactions 0 assignees View on GitHub
bug priority:major
Dominant language
Java
Stars
461
Forks
588
Avg merge
1d 8h
Merged PRs (30d)
19

Description

**[Alexey Subach](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=alexey.subach)** opened **[SUREFIRE-1470](https://issues.apache.org/jira/browse/SUREFIRE-1470?redirect=false)** and commented

When the following plugin configuration is used:

```java

org.apache.maven.plugins
maven-surefire-plugin
${surefire.version}


**/*.java

TestGroup
1

```

And there is a test that fails first time it's run, the resultant **txt** report is unexpected and only contains the result of last rerun.

Suppose we have the following test class:

```java
@Category(TestGroup.class)
public class CustomTest {

@Test
public void alwaysPassingTest() {
Assert.assertEquals(0, 0);
}

private static volatile int x = 0;

@Test
public synchronized void secondAttemptPassingTest() throws InterruptedException {
Thread.sleep(5000);
if (x++ == 0) {
Assert.fail();
}
}

}
```

The resultant xml report is all right, but the txt one is

```
-------------------------------------------------------------------------------
Test set: CustomTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.063 s - in CustomTest
```

Which is basically incorrect. The **txt** file is regenerated several times during the test run.

The issue is present when groups filter (either exclusion or inclusion) is present. When there is no group filter and only rerunFailingTestsCount is configured, then the resultant report is the following one:

```
-------------------------------------------------------------------------------
Test set: CustomTest
-------------------------------------------------------------------------------
Tests run: 3, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.065 s <<< FAILURE! - in CustomTest
secondAttemptPassingTest(CustomTest) Time elapsed: 0.009 s <<< FAILURE!
java.lang.AssertionError
at CustomTest.secondAttemptPassingTest(CustomTest.java:18)
```

When no group filter is configured, Junit4Provider instead of JunitCore provider is picked up and they seem to handle those cases differently.

The situation is worsened by the fact that TeamCity is not able to parse the results correctly when the groups are configured along with rerunFailingTestsCount and it marks the tests that passed after rerun as failed, although the overall Maven result is SUCCESS in both cases.

The simple Maven project to reproduce the issue is attached.

---

**Attachments:**
- [test.zip](https://issues.apache.org/jira/secure/attachment/12909036/test.zip) (_4.87 kB_)

Contributor guide

Open the contributing guide

Research direction

Start with the attached test.zip and reproduce the Maven run using groups together with rerunFailingTestsCount. Compare the generated TXT and XML reports for grouped and ungrouped runs, then trace the provider and report-generation paths involved. Done means the TXT report preserves the correct aggregate rerun result and does not cause passed-after-rerun tests to be reported as failed.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.