Repository: maven-surefire
Updated Branches:
  refs/heads/master 1ec371b47 -> 7bfebd06f


[SUREFIRE-1122] fix XML report for the combination of JUnit parallel and 
rerunFailingTests, by making the StatelessXmlReporter stateless again


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/a0c3283b
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/a0c3283b
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/a0c3283b

Branch: refs/heads/master
Commit: a0c3283bea494dcfd2225463c3f11a9bec37b1c8
Parents: 1ec371b
Author: Andreas Gudian <agud...@apache.org>
Authored: Thu Dec 11 21:29:05 2014 +0100
Committer: Andreas Gudian <agud...@apache.org>
Committed: Thu Dec 11 21:29:05 2014 +0100

----------------------------------------------------------------------
 .../surefire/StartupReportConfiguration.java    | 13 +++-
 .../surefire/report/StatelessXmlReporter.java   |  8 +-
 .../report/StatelessXmlReporterTest.java        | 20 ++++-
 .../Surefire1122ParallelAndFlakyTestsIT.java    | 50 ++++++++++++
 .../pom.xml                                     | 82 ++++++++++++++++++++
 .../src/test/java/test/FlakyTest.java           | 41 ++++++++++
 6 files changed, 206 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a0c3283b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java
----------------------------------------------------------------------
diff --git 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java
 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java
index 12837ed..5e34acb 100644
--- 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java
+++ 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java
@@ -21,13 +21,19 @@ package org.apache.maven.plugin.surefire;
 
 import java.io.File;
 import java.io.PrintStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.Properties;
+
 import org.apache.maven.plugin.surefire.report.ConsoleOutputFileReporter;
 import org.apache.maven.plugin.surefire.report.ConsoleReporter;
 import org.apache.maven.plugin.surefire.report.DirectConsoleOutput;
 import org.apache.maven.plugin.surefire.report.FileReporter;
 import org.apache.maven.plugin.surefire.report.StatelessXmlReporter;
 import org.apache.maven.plugin.surefire.report.TestcycleConsoleOutputReceiver;
+import org.apache.maven.plugin.surefire.report.WrappedReportEntry;
 import org.apache.maven.plugin.surefire.runorder.StatisticsReporter;
 
 import javax.annotation.Nonnull;
@@ -72,6 +78,8 @@ public class StartupReportConfiguration
 
     public static final String PLAIN_REPORT_FORMAT = ConsoleReporter.PLAIN;
 
+    private final Map<String, Map<String, List<WrappedReportEntry>>> 
testClassMethodRunHistoryMap;
+
     @SuppressWarnings( "checkstyle:parameternumber" )
     public StartupReportConfiguration( boolean useFile, boolean printSummary, 
String reportFormat,
                                        boolean redirectTestOutputToFile, 
boolean disableXmlReport,
@@ -92,6 +100,9 @@ public class StartupReportConfiguration
         this.originalSystemOut = System.out;
         this.originalSystemErr = System.err;
         this.rerunFailingTestsCount = rerunFailingTestsCount;
+        this.testClassMethodRunHistoryMap =
+                        Collections.synchronizedMap(
+                             new HashMap<String, Map<String, 
List<WrappedReportEntry>>>() );
     }
 
     public static StartupReportConfiguration defaultValue()
@@ -153,7 +164,7 @@ public class StartupReportConfiguration
         if ( !isDisableXmlReport() )
         {
             return new StatelessXmlReporter( reportsDirectory, 
reportNameSuffix, trimStackTrace,
-                                             rerunFailingTestsCount );
+                                             rerunFailingTestsCount, 
testClassMethodRunHistoryMap );
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a0c3283b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java
----------------------------------------------------------------------
diff --git 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java
 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java
index e37940a..ae78e15 100644
--- 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java
+++ 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java
@@ -36,7 +36,6 @@ import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Enumeration;
-import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -96,16 +95,17 @@ public class StatelessXmlReporter
 
     // Map between test class name and a map between test method name
     // and the list of runs for each test method
-    private Map<String, Map<String, List<WrappedReportEntry>>> 
testClassMethodRunHistoryMap =
-        Collections.synchronizedMap( new HashMap<String, Map<String, 
List<WrappedReportEntry>>>() );
+    private final Map<String, Map<String, List<WrappedReportEntry>>> 
testClassMethodRunHistoryMap;
 
     public StatelessXmlReporter( File reportsDirectory, String 
reportNameSuffix, boolean trimStackTrace,
-                                 int rerunFailingTestsCount )
+                                 int rerunFailingTestsCount,
+                                 Map<String, Map<String, 
List<WrappedReportEntry>>> testClassMethodRunHistoryMap )
     {
         this.reportsDirectory = reportsDirectory;
         this.reportNameSuffix = reportNameSuffix;
         this.trimStackTrace = trimStackTrace;
         this.rerunFailingTestsCount = rerunFailingTestsCount;
+        this.testClassMethodRunHistoryMap = testClassMethodRunHistoryMap;
     }
 
     public void testSetCompleted( WrappedReportEntry testSetReportEntry, 
TestSetStats testSetStats )

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a0c3283b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporterTest.java
----------------------------------------------------------------------
diff --git 
a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporterTest.java
 
b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporterTest.java
index 4facf9e..6c2982a 100644
--- 
a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporterTest.java
+++ 
b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporterTest.java
@@ -21,6 +21,7 @@ package org.apache.maven.plugin.surefire.report;
 
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
+
 import 
org.apache.maven.plugin.surefire.booterclient.output.DeserializedStacktraceWriter;
 import org.apache.maven.shared.utils.StringUtils;
 import org.apache.maven.shared.utils.xml.Xpp3Dom;
@@ -34,13 +35,18 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 @SuppressWarnings( "ResultOfMethodCallIgnored" )
 public class StatelessXmlReporterTest
     extends TestCase
 {
 
-    private StatelessXmlReporter reporter = new StatelessXmlReporter( new 
File( "." ), null, false, 0 );
+    private StatelessXmlReporter reporter = new StatelessXmlReporter( new 
File( "." ), null, false, 0,
+                    Collections.synchronizedMap( new HashMap<String, 
Map<String, List<WrappedReportEntry>>>() ) );
 
     private ReportEntry reportEntry;
 
@@ -131,7 +137,8 @@ public class StatelessXmlReporterTest
                                     ReportEntryType.ERROR, 13, stdOut, stdErr 
);
 
         stats.testSucceeded( t2 );
-        StatelessXmlReporter reporter = new StatelessXmlReporter( new File( 
"." ), null, false, 0 );
+        StatelessXmlReporter reporter = new StatelessXmlReporter( new File( 
"." ), null, false, 0,
+                        Collections.synchronizedMap( new HashMap<String, 
Map<String, List<WrappedReportEntry>>>() ) );
         reporter.testSetCompleted( testSetReportEntry, stats );
 
         FileInputStream fileInputStream = new FileInputStream( 
expectedReportFile );
@@ -210,7 +217,14 @@ public class StatelessXmlReporterTest
         rerunStats.testSucceeded( testTwoSecondError );
         rerunStats.testSucceeded( testThreeSecondRun );
 
-        StatelessXmlReporter reporter = new StatelessXmlReporter( new File( 
"." ), null, false, 1 );
+        StatelessXmlReporter reporter =
+            new StatelessXmlReporter(
+                                      new File( "." ),
+                                      null,
+                                      false,
+                                      1,
+                                      new HashMap<String, Map<String, 
List<WrappedReportEntry>>>() );
+
         reporter.testSetCompleted( testSetReportEntry, stats );
         reporter.testSetCompleted( testSetReportEntry, rerunStats );
 

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a0c3283b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1122ParallelAndFlakyTestsIT.java
----------------------------------------------------------------------
diff --git 
a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1122ParallelAndFlakyTestsIT.java
 
b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1122ParallelAndFlakyTestsIT.java
new file mode 100644
index 0000000..e8fab4e
--- /dev/null
+++ 
b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1122ParallelAndFlakyTestsIT.java
@@ -0,0 +1,50 @@
+package org.apache.maven.surefire.its.jiras;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.it.VerificationException;
+import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
+import org.apache.maven.surefire.its.fixture.SurefireLauncher;
+import org.junit.Test;
+
+/**
+ * @author agudian
+ * @see {@linkplain https://jira.codehaus.org/browse/SUREFIRE-1122}
+ */
+public class Surefire1122ParallelAndFlakyTestsIT
+    extends SurefireJUnit4IntegrationTestCase
+{
+    @Test
+    public void nonParallelCreatesCorrectReport()
+    {
+        unpack( "surefire-1122-parallel-and-flakyTests" )
+            .executeTest()
+            .assertTestSuiteResults( 2, 0, 0, 0, 1 );
+    }
+
+    @Test
+    public void parallelCreatesCorrectReport()
+    {
+        unpack( "surefire-1122-parallel-and-flakyTests" )
+            .activateProfile( "parallel" )
+            .executeTest()
+            .assertTestSuiteResults( 2, 0, 0, 0, 1 );
+    }
+}

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a0c3283b/surefire-integration-tests/src/test/resources/surefire-1122-parallel-and-flakyTests/pom.xml
----------------------------------------------------------------------
diff --git 
a/surefire-integration-tests/src/test/resources/surefire-1122-parallel-and-flakyTests/pom.xml
 
b/surefire-integration-tests/src/test/resources/surefire-1122-parallel-and-flakyTests/pom.xml
new file mode 100644
index 0000000..5fa0110
--- /dev/null
+++ 
b/surefire-integration-tests/src/test/resources/surefire-1122-parallel-and-flakyTests/pom.xml
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.maven.surefire</groupId>
+    <artifactId>it-parent</artifactId>
+    <version>1.0</version>
+    <relativePath>../pom.xml</relativePath>
+  </parent>
+  <groupId>org.apache.maven.plugins.surefire</groupId>
+  <artifactId>jiras-surefire-1122</artifactId>
+  <version>1.0</version>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.11</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <dependencies>
+          <dependency>
+            <groupId>org.apache.maven.surefire</groupId>
+            <artifactId>surefire-junit47</artifactId>
+            <version>${surefire.version}</version>
+          </dependency>
+        </dependencies>
+        <configuration>
+          <rerunFailingTestsCount>2</rerunFailingTestsCount>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <profiles>
+    <profile>
+      <id>parallel</id>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+              <useUnlimitedThreads>true</useUnlimitedThreads>
+              <forkCount>0</forkCount>
+              <parallel>classes</parallel>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+</project>

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a0c3283b/surefire-integration-tests/src/test/resources/surefire-1122-parallel-and-flakyTests/src/test/java/test/FlakyTest.java
----------------------------------------------------------------------
diff --git 
a/surefire-integration-tests/src/test/resources/surefire-1122-parallel-and-flakyTests/src/test/java/test/FlakyTest.java
 
b/surefire-integration-tests/src/test/resources/surefire-1122-parallel-and-flakyTests/src/test/java/test/FlakyTest.java
new file mode 100644
index 0000000..fc7b443
--- /dev/null
+++ 
b/surefire-integration-tests/src/test/resources/surefire-1122-parallel-and-flakyTests/src/test/java/test/FlakyTest.java
@@ -0,0 +1,41 @@
+package test;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.junit.Test;
+
+public class FlakyTest
+{
+    private static int x = 1;
+
+    @Test
+    public void failsOnFirstExecution()
+    {
+        if ( x++ < 2 )
+        {
+            org.junit.Assert.fail( "First execution always fails. Try again." 
);
+        }
+    }
+
+    @Test
+    public void alwaysPasses()
+    {
+    }
+}

Reply via email to