You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2008/10/12 12:11:13 UTC

svn commit: r703776 - /maven/core-integration-testing/trunk/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java

Author: bentmann
Date: Sun Oct 12 03:11:12 2008
New Revision: 703776

URL: http://svn.apache.org/viewvc?rev=703776&view=rev
Log:
o Printed elapsed test time to highlight long running tests

Modified:
    maven/core-integration-testing/trunk/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java

Modified: maven/core-integration-testing/trunk/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java?rev=703776&r1=703775&r2=703776&view=diff
==============================================================================
--- maven/core-integration-testing/trunk/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java (original)
+++ maven/core-integration-testing/trunk/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java Sun Oct 12 03:11:12 2008
@@ -28,6 +28,9 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintStream;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.util.Locale;
 
 import junit.framework.TestCase;
 
@@ -43,6 +46,17 @@
      */
     private static PrintStream out = System.out;
 
+    /**
+     * The format for elapsed time.
+     */
+    private static final DecimalFormat SECS_FORMAT =
+        new DecimalFormat( "(0.0 s)", new DecimalFormatSymbols( Locale.ENGLISH ) );
+
+    /**
+     * The zero-based column index where to print the test result.
+     */
+    private static final int RESULT_COLUMN = 60;
+    
     private boolean skip;
 
     private ArtifactVersion mavenVersion;
@@ -129,11 +143,13 @@
     protected void runTest()
         throws Throwable
     {
-        out.print( getITName() + "(" + getName() + ").." );
+        String line = getTestName() + "..";
+        out.print( line );
 
         if ( skip )
         {
-            out.println( " Skipping - version " + getMavenVersion() + " not in range " + versionRange );
+            out.println( pad( RESULT_COLUMN - line.length() ) + "SKIPPED - version " + getMavenVersion()
+                + " not in range " + versionRange );
             return;
         }
 
@@ -142,14 +158,19 @@
             setupLocalRepo();
         }
 
+        long milliseconds = System.currentTimeMillis();
         try
         {
             super.runTest();
-            out.println( " Ok" );
+            milliseconds = System.currentTimeMillis() - milliseconds;
+            String result = "OK " + formatTime( milliseconds );
+            out.println( pad( RESULT_COLUMN - line.length() ) + result );
         }
         catch ( Throwable t )
         {
-            out.println( " Failure" );
+            milliseconds = System.currentTimeMillis() - milliseconds;
+            String result = "FAILURE " + formatTime( milliseconds );
+            out.println( pad( RESULT_COLUMN - line.length() ) + result );
             throw t;
         }
     }
@@ -164,6 +185,32 @@
         return simpleName;
     }
 
+    private String getTestName()
+    {
+        String className = getITName();
+        String methodName = getName();
+        if ( methodName.startsWith( "test" ) )
+        {
+            methodName = methodName.substring( 4 );
+        }
+        return className + '(' + methodName + ')';
+    }
+
+    private String pad( int chars )
+    {
+        StringBuffer buffer = new StringBuffer( 128 );
+        for ( int i = 0; i < chars; i++ )
+        {
+            buffer.append( '.' );
+        }
+        return buffer.toString();
+    }
+
+    private String formatTime( long milliseconds )
+    {
+        return SECS_FORMAT.format( milliseconds / 1000.0 );
+    }
+
     protected File setupLocalRepo()
         throws IOException
     {