Uploaded image for project: 'Maven Surefire'
  1. Maven Surefire
  2. SUREFIRE-1821

Broken junit report when parallel and rerunFailingTestsCount configureation is used

    XMLWordPrintableJSON

Details

    Description

      Description:

      When using parallel configuration with rerunFailingTestsCount bad xml report is generated for a failing test.

      How to reproduce:

      1. Configure forkCount, parallel and rerun count:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M5</version>
        <executions>
          <execution>
            <goals>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <rerunFailingTestsCount>1</rerunFailingTestsCount>
          <forkCount>1</forkCount>
          <threadCount>1</threadCount>
          <parallel>all</parallel>
          <redirectTestOutputToFile>true</redirectTestOutputToFile>
        </configuration>
      </plugin>
      

      2. Create a failing test that outputs more than 1m characters:

      public class AppTest {
          @Test
          public void testBug() {
              for(int i = 0;  i < 100000; i++){
                  System.out.println("Some output longer than 10 character");
              }
              throw new NullPointerException();
          }
      }
      

      3. Run the test and check the report - you will see unexpected end of xml file:

          ...
          <property name="sun.io.unicode.encoding" value="UnicodeBig"/>
          <property name="java.class.version" value="52.0"/>
        </properties>
        <testcase name="testBug" classname="com.mycompany.app.AppTest" time="0.015">
          <error type="java.lang.NullPointerException"><![CDATA[java.lang.NullPointerException
              at com.mycompany.app.AppTest.testBug(AppTest.java:12)
      ]]></error>
          <system-out><![CDATA[  <-- EOF
      

      Possible cause:

      It seems that Junit 4.7 Runner considers each rerun as a separate test set, so sends testSetCompleted event each time, but after the first event DeferredFileOutputStream and associated with it temp file gets freed(deleted), however testSetCompleted event for rerun still tries to write something there. If temp file isn't yet created (still in memory) then there will be no bug and it gets created only after 1m characters were written to the stream. I wasn't able to understand wether multiple testSetCompleted events is a bug here or a "rerun" trying to write to DeferredFileOutputStream of initial test run.

       

      Project to reproduce:

      https://github.com/himos/surefire-report-bug

      Attachments

        Issue Links

          Activity

            People

              tibordigana Tibor Digana
              himos Pavel Pustovoyt
              Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: