maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krosenv...@apache.org
Subject svn commit: r1048982 - in /maven/surefire/trunk: surefire-api/src/main/java/org/apache/maven/surefire/report/ surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/
Date Tue, 14 Dec 2010 08:46:43 GMT
Author: krosenvold
Date: Tue Dec 14 08:46:43 2010
New Revision: 1048982

URL: http://svn.apache.org/viewvc?rev=1048982&view=rev
Log:
[SUREFIRE-664] Display proper execution times when running in parallel

Modified:
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractTextReporter.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/DefaultReportEntry.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReportEntry.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestMethod.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java?rev=1048982&r1=1048981&r2=1048982&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java
Tue Dec 14 08:46:43 2010
@@ -35,9 +35,9 @@ public abstract class AbstractReporter
 
     protected int failures;
 
-    protected long startTime;
+    private long startTime;
 
-    protected long endTime;
+    private long endTime;
 
     private NumberFormat numberFormat = NumberFormat.getInstance( Locale.ENGLISH );
 
@@ -65,6 +65,7 @@ public abstract class AbstractReporter
     {
         this.trimStackTrace = trimStackTrace.booleanValue();
     }
+
     public void writeFooter( String footer )
     {
         writeMessage( footer );
@@ -199,4 +200,10 @@ public abstract class AbstractReporter
         }
         return trimStackTrace ? writer.writeTrimmedTraceToString() : writer.writeTraceToString();
     }
+
+    protected long getActualRunTime( ReportEntry reportEntry )
+    {
+        final Integer clientSpecifiedElapsed = reportEntry.getElapsed();
+        return clientSpecifiedElapsed != null ? clientSpecifiedElapsed.intValue() : endTime
- startTime;
+    }
 }

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractTextReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractTextReporter.java?rev=1048982&r1=1048981&r2=1048982&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractTextReporter.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractTextReporter.java
Tue Dec 14 08:46:43 2010
@@ -152,7 +152,7 @@ public abstract class AbstractTextReport
     {
         super.testSetCompleted( report );
 
-        writeMessage( getTestSetSummary() );
+        writeMessage( getTestSetSummary( report ) );
 
         if ( format.equals( BRIEF ) || format.equals( PLAIN ) )
         {
@@ -163,7 +163,7 @@ public abstract class AbstractTextReport
         }
     }
 
-    protected String getTestSetSummary()
+    protected String getTestSetSummary( ReportEntry report )
     {
         StringBuffer buf = new StringBuffer();
 
@@ -176,7 +176,10 @@ public abstract class AbstractTextReport
         buf.append( ", Skipped: " );
         buf.append( skipped );
         buf.append( ", Time elapsed: " );
-        buf.append( elapsedTimeAsString( System.currentTimeMillis() - testSetStartTime )
);
+        int elapsed = report.getElapsed() != null
+            ? report.getElapsed().intValue()
+            : (int) ( System.currentTimeMillis() - testSetStartTime );
+        buf.append( elapsedTimeAsString( elapsed ) );
         buf.append( " sec" );
 
         if ( failures > 0 || errors > 0 )
@@ -190,7 +193,7 @@ public abstract class AbstractTextReport
     protected String getElapsedTimeSummary( ReportEntry report )
     {
         StringBuffer reportContent = new StringBuffer();
-        long runTime = this.endTime - this.startTime;
+        long runTime = getActualRunTime( report );
 
         reportContent.append( report.getName() );
         reportContent.append( "  Time elapsed: " );

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/DefaultReportEntry.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/DefaultReportEntry.java?rev=1048982&r1=1048981&r2=1048982&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/DefaultReportEntry.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/DefaultReportEntry.java
Tue Dec 14 08:46:43 2010
@@ -22,24 +22,37 @@ package org.apache.maven.surefire.report
 /**
  * @author Kristian Rosenvold
  */
-public class DefaultReportEntry extends ReportEntry
+public class DefaultReportEntry
+    extends ReportEntry
 {
     public DefaultReportEntry( String source, String name, String message )
     {
-        super( source, name, null, message, null );
+        super( source, name, null, message, null);
+    }
+
+    public DefaultReportEntry( String source, String name, String message, Integer elapsed
)
+    {
+        super( source, name, null, message, null, elapsed );
     }
 
     public DefaultReportEntry( String source, String name, String group, String message )
     {
-        super( source, name, group, message, null );
+        super( source, name, group, message, null, null );
     }
 
     public DefaultReportEntry( String source, String name, String message, StackTraceWriter
stackTraceWriter )
     {
-        super( source, name, null, message, stackTraceWriter );
+        super( source, name, null, message, stackTraceWriter, null );
     }
 
-    public static ReportEntry nameGroup(String name, String group){
-        return new ReportEntry( name, group);
+    public DefaultReportEntry( String source, String name, String message, StackTraceWriter
stackTraceWriter,
+                               Integer elapsed )
+    {
+        super( source, name, null, message, stackTraceWriter, elapsed );
+    }
+
+    public static ReportEntry nameGroup( String name, String group )
+    {
+        return new ReportEntry( name, group );
     }
 }

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReportEntry.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReportEntry.java?rev=1048982&r1=1048981&r2=1048982&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReportEntry.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReportEntry.java
Tue Dec 14 08:46:43 2010
@@ -36,26 +36,35 @@ public class ReportEntry
 
     private final StackTraceWriter stackTraceWriter;
 
+    private final Integer elapsed;
+
     protected ReportEntry( String name, String group )
     {
         this.name = name;
         this.group = group;
         this.stackTraceWriter = null;
+        this.elapsed = null;
         this.message = null;
         this.source = null;
     }
 
     public ReportEntry( String source, String name, String message )
     {
-        this( source, name, null, message, null );
+        this( source, name, null, message, null, null );
     }
 
     public ReportEntry( String source, String name, String message, StackTraceWriter stackTraceWriter
)
     {
-        this( source, name, null, message, stackTraceWriter );
+        this( source, name, null, message, stackTraceWriter, null );
+    }
+
+    public ReportEntry( String source, String name, String group, String message, StackTraceWriter
stackTraceWriter )
+    {
+        this( source, name, group, message, stackTraceWriter, null );
     }
 
-    protected ReportEntry( String source, String name, String group, String message, StackTraceWriter
stackTraceWriter )
+    public ReportEntry( String source, String name, String group, String message, StackTraceWriter
stackTraceWriter,
+                        Integer elapsed )
     {
         if ( source == null )
         {
@@ -79,6 +88,8 @@ public class ReportEntry
         this.message = message;
 
         this.stackTraceWriter = stackTraceWriter;
+
+        this.elapsed = elapsed;
     }
 
     public String getSourceName()
@@ -106,6 +117,11 @@ public class ReportEntry
         return stackTraceWriter;
     }
 
+    public Integer getElapsed()
+    {
+        return elapsed;
+    }
+
     public boolean equals( Object obj )
     {
         if ( !( obj instanceof ReportEntry ) )

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java?rev=1048982&r1=1048981&r2=1048982&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
Tue Dec 14 08:46:43 2010
@@ -156,7 +156,7 @@ public class XMLReporter
     {
         super.testSucceeded( report );
 
-        long runTime = this.endTime - this.startTime;
+        long runTime = getActualRunTime(  report );
 
         Xpp3Dom testCase = createTestElement( report, runTime );
 
@@ -213,7 +213,7 @@ public class XMLReporter
 
     private void writeTestProblems( ReportEntry report, String stdOut, String stdErr, String
name )
     {
-        long runTime = endTime - startTime;
+        long runTime = getActualRunTime( report );
 
         Xpp3Dom testCase = createTestElement( report, runTime );
 

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestMethod.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestMethod.java?rev=1048982&r1=1048981&r2=1048982&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestMethod.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestMethod.java
Tue Dec 14 08:46:43 2010
@@ -40,6 +40,10 @@ class TestMethod
 {
     private final Description description;
 
+    private final long startTime;
+
+    private long endTime;
+
     private volatile Failure testFailure;
 
     private volatile Failure testAssumptionFailure;
@@ -55,12 +59,14 @@ class TestMethod
     public TestMethod( Description description )
     {
         this.description = description;
+        startTime = System.currentTimeMillis();
     }
 
 
     public void testFinished()
         throws Exception
     {
+        setEndTime();
     }
 
 
@@ -68,21 +74,34 @@ class TestMethod
         throws Exception
     {
         ignored = description;
-
+        setEndTime();
     }
 
     public void testFailure( Failure failure )
         throws Exception
     {
         this.testFailure = failure;
+        setEndTime();
     }
 
 
     public void testAssumptionFailure( Failure failure )
     {
         this.testAssumptionFailure = failure;
+        setEndTime();
+    }
+
+    private void setEndTime()
+    {
+        this.endTime = System.currentTimeMillis();
     }
 
+    public int getElapsed()
+    {
+        return (int) ( endTime - startTime );
+    }
+
+
     public void replay( Reporter reporter )
         throws Exception
     {
@@ -126,14 +145,15 @@ class TestMethod
     {
         String rawString = bundle.getString( rawString2 );
         return new DefaultReportEntry( description.getTestClass().getCanonicalName(), description.getDisplayName(),
-                                       rawString );
+                                       rawString, getElapsed() );
     }
 
     private ReportEntry createFailureEntry( Failure failure, String rawString2 )
     {
         String rawString = bundle.getString( rawString2 );
         return new DefaultReportEntry( failure.getDescription().getTestClass().getCanonicalName(),
-                                       failure.getTestHeader(), rawString, new JUnitCoreStackTraceWriter(
failure ) );
+                                       failure.getTestHeader(), rawString, new JUnitCoreStackTraceWriter(
failure ),
+                                       getElapsed() );
     }
 
 

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java?rev=1048982&r1=1048981&r2=1048982&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java
Tue Dec 14 08:46:43 2010
@@ -70,7 +70,12 @@ public class TestSet
 
         try
         {
-            ReportEntry report = createReportEntry( "testSetStarting" );
+            int elapsed = 0;
+            for ( TestMethod testMethod : testMethods )
+            {
+                elapsed += testMethod.getElapsed();
+            }
+            ReportEntry report = createReportEntry( "testSetStarting", null );
 
             target.testSetStarting( report );
 
@@ -78,7 +83,7 @@ public class TestSet
             {
                 testMethod.replay( target );
             }
-            report = createReportEntry( "testSetCompletedNormally" );
+            report = createReportEntry( "testSetCompletedNormally", elapsed );
 
             target.testSetCompleted( report );
 
@@ -97,13 +102,13 @@ public class TestSet
         return testMethod;
     }
 
-    private ReportEntry createReportEntry( String rawString2 )
+    private ReportEntry createReportEntry( String rawString2, Integer elapsed )
     {
         String rawString = bundle.getString( rawString2 );
         boolean isJunit3 = testSetDescription.getTestClass() == null;
         String classNameToUse =
             isJunit3 ? testSetDescription.getChildren().get( 0 ).getClassName() : testSetDescription.getClassName();
-        return new DefaultReportEntry( classNameToUse, classNameToUse, rawString );
+        return new DefaultReportEntry( classNameToUse, classNameToUse, rawString, elapsed);
     }
 
     public void incrementTestMethodCount()



Mime
View raw message