You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ag...@apache.org on 2014/10/11 23:05:16 UTC

git commit: [SUREFIRE-1088] fix reported execution time if a test breaks in @BeforeClass, or if a complete test class is marked as @Ignored

Repository: maven-surefire
Updated Branches:
  refs/heads/master 6d50bf678 -> 080aa5f61


[SUREFIRE-1088] fix reported execution time if a test breaks in @BeforeClass, or if a complete test class is marked as @Ignored


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

Branch: refs/heads/master
Commit: 080aa5f612382cd1bf6e47c4322bd855ad3b4fed
Parents: 6d50bf6
Author: Andreas Gudian <ag...@apache.org>
Authored: Sat Oct 11 23:05:03 2014 +0200
Committer: Andreas Gudian <ag...@apache.org>
Committed: Sat Oct 11 23:05:03 2014 +0200

----------------------------------------------------------------------
 .../surefire/report/TestSetRunListener.java     | 31 ++++++++++++++--
 .../plugin/surefire/report/TestSetStats.java    | 18 ++++++++-
 .../its/jiras/Surefire943ReportContentIT.java   | 37 +++++++++++++++----
 .../test/java/org/sample/module/My1Test.java    |  3 --
 .../test/java/org/sample/module/My2Test.java    |  3 --
 .../test/java/org/sample/module/My3Test.java    |  3 --
 .../test/java/org/sample/module/My4Test.java    |  5 ---
 .../test/java/org/sample/module/My5Test.java    | 39 ++++++++++++++++++++
 8 files changed, 111 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/080aa5f6/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java
index ca2403d..d4c0263 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java
@@ -19,16 +19,17 @@ package org.apache.maven.plugin.surefire.report;
  * under the License.
  */
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.maven.plugin.surefire.runorder.StatisticsReporter;
+import org.apache.maven.shared.utils.StringUtils;
 import org.apache.maven.surefire.report.ConsoleLogger;
 import org.apache.maven.surefire.report.ConsoleOutputReceiver;
 import org.apache.maven.surefire.report.ReportEntry;
 import org.apache.maven.surefire.report.RunListener;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  * Reports data for a single test set.
  * <p/>
@@ -40,6 +41,8 @@ public class TestSetRunListener
 {
     private final TestSetStats detailsForThis;
 
+    private ReportEntry lastSkipped;
+
     private List<TestMethodStats> testMethodStats;
 
     private Utf8RecodingDeferredFileOutputStream testStdOut = initDeferred( "stdout" );
@@ -109,6 +112,8 @@ public class TestSetRunListener
 
     public void testSetStarting( ReportEntry report )
     {
+        checkForUnfinishedTestSetDueToSkip( report );
+
         detailsForThis.testSetStart();
         if ( consoleReporter != null )
         {
@@ -180,6 +185,8 @@ public class TestSetRunListener
 
     public void testError( ReportEntry reportEntry )
     {
+        checkForUnfinishedTestSetDueToSkip( reportEntry );
+
         WrappedReportEntry wrapped = wrap( reportEntry, ReportEntryType.error );
         detailsForThis.testError( wrapped );
         if ( statisticsReporter != null )
@@ -191,6 +198,8 @@ public class TestSetRunListener
 
     public void testFailed( ReportEntry reportEntry )
     {
+        checkForUnfinishedTestSetDueToSkip( reportEntry );
+
         WrappedReportEntry wrapped = wrap( reportEntry, ReportEntryType.failure );
         detailsForThis.testFailure( wrapped );
         if ( statisticsReporter != null )
@@ -206,7 +215,12 @@ public class TestSetRunListener
 
     public void testSkipped( ReportEntry reportEntry )
     {
+        checkForUnfinishedTestSetDueToSkip( reportEntry );
+
+        lastSkipped = reportEntry;
+
         WrappedReportEntry wrapped = wrap( reportEntry, ReportEntryType.skipped );
+
         detailsForThis.testSkipped( wrapped );
         if ( statisticsReporter != null )
         {
@@ -215,6 +229,15 @@ public class TestSetRunListener
         clearCapture();
     }
 
+    private void checkForUnfinishedTestSetDueToSkip( ReportEntry reportEntry )
+    {
+        if ( lastSkipped != null && !StringUtils.equals( lastSkipped.getSourceName(), reportEntry.getSourceName() ) ) {
+            // a new test class was started to be processed, but a skipped test class was not yet marked as completed
+            testSetCompleted( lastSkipped );
+            lastSkipped = null;
+        }
+    }
+
     public void testAssumptionFailure( ReportEntry report )
     {
         testSkipped( report );

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/080aa5f6/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetStats.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetStats.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetStats.java
index a175b0a..8391ff9 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetStats.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetStats.java
@@ -58,12 +58,26 @@ public class TestSetStats
 
     public int getElapsedSinceTestSetStart()
     {
-        return (int) ( System.currentTimeMillis() - testSetStartAt );
+        if ( testSetStartAt > 0 )
+        {
+            return (int) ( System.currentTimeMillis() - testSetStartAt );
+        }
+        else
+        {
+            return 0;
+        }
     }
 
     public int getElapsedSinceLastStart()
     {
-        return (int) ( System.currentTimeMillis() - lastStartAt );
+        if ( lastStartAt > 0 )
+        {
+            return (int) ( System.currentTimeMillis() - lastStartAt );
+        }
+        else
+        {
+            return 0;
+        }
     }
 
     public void testSetStart()

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/080aa5f6/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire943ReportContentIT.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire943ReportContentIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire943ReportContentIT.java
index 32aedbf..f702999 100644
--- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire943ReportContentIT.java
+++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire943ReportContentIT.java
@@ -20,11 +20,11 @@ package org.apache.maven.surefire.its.jiras;
  */
 
 import java.io.FileNotFoundException;
+
 import org.apache.maven.shared.utils.xml.Xpp3Dom;
 import org.apache.maven.shared.utils.xml.Xpp3DomBuilder;
 import org.apache.maven.surefire.its.fixture.OutputValidator;
 import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
-
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -49,19 +49,40 @@ public class Surefire943ReportContentIT
     private void doTest( String parallelMode )
         throws Exception
     {
-        OutputValidator validator = unpack( "surefire-943-report-content" )
-                .maven()
-                .sysProp( "parallel", parallelMode )
-                .sysProp( "threadCount", 4 )
-                .withFailure()
-                .executeTest();
+        OutputValidator validator =
+            unpack( "surefire-943-report-content" ).maven().sysProp( "parallel", parallelMode ).sysProp( "threadCount",
+                                                                                                         4 ).withFailure().executeTest();
 
-        validator.assertTestSuiteResults( 9, 0, 3, 3 );
+        validator.assertTestSuiteResults( 10, 1, 3, 3 );
 
         validate( validator, "org.sample.module.My1Test", 1 );
         validate( validator, "org.sample.module.My2Test", 1 );
         validate( validator, "org.sample.module.My3Test", 0 );
         validateSkipped( validator, "org.sample.module.My4Test" );
+        validateFailInBeforeClass( validator, "org.sample.module.My5Test" );
+    }
+
+    private void validateFailInBeforeClass( OutputValidator validator, String className )
+        throws FileNotFoundException
+    {
+        Xpp3Dom[] children = readTests( validator, className );
+
+        Assert.assertEquals( 1, children.length );
+
+        Xpp3Dom child = children[0];
+
+        Assert.assertEquals( className, child.getAttribute( "classname" ) );
+        Assert.assertEquals( className, child.getAttribute( "name" ) );
+
+        Assert.assertEquals( "Expected error tag for failed BeforeClass method for " + className, 1,
+                             child.getChildren( "error" ).length );
+
+        Assert.assertTrue( "time for test failure in BeforeClass is expected to be positive",
+                           Double.compare( Double.parseDouble( child.getAttribute( "time" ) ), 0.0d ) >= 0 );
+
+        Assert.assertTrue( "time for test failure in BeforeClass is expected to be resonably low",
+                           Double.compare( Double.parseDouble( child.getAttribute( "time" ) ), 2.0d ) <= 0 );
+
     }
 
     private void validateSkipped( OutputValidator validator, String className )

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/080aa5f6/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My1Test.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My1Test.java b/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My1Test.java
index 02be450..0d996f4 100644
--- a/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My1Test.java
+++ b/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My1Test.java
@@ -21,9 +21,6 @@ package org.sample.module;
 
 import static org.junit.Assert.fail;
 
-import java.lang.management.ManagementFactory;
-
-import org.junit.Before;
 import org.junit.Test;
 import org.junit.Ignore;
 

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/080aa5f6/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My2Test.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My2Test.java b/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My2Test.java
index cd0d83c..ac4e338 100644
--- a/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My2Test.java
+++ b/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My2Test.java
@@ -21,9 +21,6 @@ package org.sample.module;
 
 import static org.junit.Assert.fail;
 
-import java.lang.management.ManagementFactory;
-
-import org.junit.Before;
 import org.junit.Test;
 import org.junit.Ignore;
 

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/080aa5f6/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My3Test.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My3Test.java b/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My3Test.java
index 6fd712b..0a432e9 100644
--- a/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My3Test.java
+++ b/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My3Test.java
@@ -21,9 +21,6 @@ package org.sample.module;
 
 import static org.junit.Assert.fail;
 
-import java.lang.management.ManagementFactory;
-
-import org.junit.Before;
 import org.junit.Test;
 
 public class My3Test {

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/080aa5f6/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My4Test.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My4Test.java b/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My4Test.java
index b19de37..c500c1e 100644
--- a/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My4Test.java
+++ b/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My4Test.java
@@ -19,11 +19,6 @@ package org.sample.module;
  * under the License.
  */
 
-import static org.junit.Assert.fail;
-
-import java.lang.management.ManagementFactory;
-
-import org.junit.Before;
 import org.junit.Test;
 import org.junit.Ignore;
 

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/080aa5f6/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My5Test.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My5Test.java b/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My5Test.java
new file mode 100644
index 0000000..1e30741
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-943-report-content/src/test/java/org/sample/module/My5Test.java
@@ -0,0 +1,39 @@
+package org.sample.module;
+
+/*
+ * 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.BeforeClass;
+import org.junit.Test;
+
+public class My5Test {
+
+    @BeforeClass 
+    public static void failsOnBeforeClass()
+    {
+        throw new RuntimeException("always fails before class");
+    }
+    
+    @Test
+    public void neverExecuted()
+        throws Exception
+    {
+        
+    }
+}