maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dfabul...@apache.org
Subject svn commit: r598205 - in /maven/surefire/trunk: surefire-api/src/main/java/org/apache/maven/surefire/suite/ surefire-providers/surefire-testng/ surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/
Date Mon, 26 Nov 2007 10:19:52 GMT
Author: dfabulich
Date: Mon Nov 26 02:19:50 2007
New Revision: 598205

URL: http://svn.apache.org/viewvc?rev=598205&view=rev
Log:
[SUREFIRE-337] Provide support for running JUnit and TestNG tests together

Modified:
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
    maven/surefire/trunk/surefire-providers/surefire-testng/pom.xml
    maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
    maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java
    maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java?rev=598205&r1=598204&r2=598205&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
Mon Nov 26 02:19:50 2007
@@ -41,7 +41,7 @@
 public abstract class AbstractDirectoryTestSuite
     implements SurefireTestSuite
 {
-    protected ResourceBundle bundle = ResourceBundle.getBundle( Surefire.SUREFIRE_BUNDLE_NAME
);
+    protected static ResourceBundle bundle = ResourceBundle.getBundle( Surefire.SUREFIRE_BUNDLE_NAME
);
 
     private static final String FS = System.getProperty( "file.separator" );
 

Modified: maven/surefire/trunk/surefire-providers/surefire-testng/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-testng/pom.xml?rev=598205&r1=598204&r2=598205&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-testng/pom.xml (original)
+++ maven/surefire/trunk/surefire-providers/surefire-testng/pom.xml Mon Nov 26 02:19:50 2007
@@ -33,6 +33,11 @@
       <artifactId>maven-artifact</artifactId>
       <version>2.0</version>
     </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+    </dependency>
   </dependencies>
   <!-- TODO: do we include both? Or just 1.5? No need for profile -->
   <profiles>

Modified: maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java?rev=598205&r1=598204&r2=598205&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
Mon Nov 26 02:19:50 2007
@@ -19,21 +19,23 @@
  * under the License.
  */
 
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
 import org.apache.maven.artifact.versioning.ArtifactVersion;
 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import org.apache.maven.surefire.report.ReportEntry;
 import org.apache.maven.surefire.report.ReporterException;
 import org.apache.maven.surefire.report.ReporterManager;
 import org.apache.maven.surefire.suite.AbstractDirectoryTestSuite;
 import org.apache.maven.surefire.testset.SurefireTestSet;
 import org.apache.maven.surefire.testset.TestSetFailedException;
 
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
 /**
  * Test suite for TestNG based on a directory of Java test classes. Can also execute JUnit
tests.
  *
@@ -106,15 +108,77 @@
             throw new IllegalStateException( "You must call locateTestSets before calling
execute" );
         }
 
-        Class[] testClasses = new Class[testSets.size()];
-        int i = 0;
+        List testNgTestClasses = new ArrayList();
+        List junitTestClasses = new ArrayList();
         for ( Iterator it = testSets.values().iterator(); it.hasNext(); )
         {
             SurefireTestSet testSet = (SurefireTestSet) it.next();
-            testClasses[i++] = testSet.getTestClass();
+            Class c = testSet.getTestClass();
+            if (junit.framework.Test.class.isAssignableFrom( c )) {
+                junitTestClasses.add( c );
+            } else {
+                testNgTestClasses.add( c );
+            }
         }
+     
+        File testNgReportsDirectory = reportsDirectory, junitReportsDirectory = reportsDirectory;
+        
+        if ( junitTestClasses.size() > 0 && testNgTestClasses.size() > 0 )
+        {
+            testNgReportsDirectory = new File( reportsDirectory, "testng-native-results");
+            junitReportsDirectory = new File( reportsDirectory, "testng-junit-results");
+        }
+        
+        startTestSuite( reporterManager, this );
+        
+        Class[] testClasses = (Class[]) testNgTestClasses.toArray( new Class[0] );
 
         TestNGExecutor.run( testClasses, this.testSourceDirectory, this.options, this.version,

-                            this.classifier, reporterManager, this, reportsDirectory );
+                            this.classifier, reporterManager, this, testNgReportsDirectory
);
+        
+        if (junitTestClasses.size() > 0) {
+            testClasses = (Class[]) junitTestClasses.toArray( new Class[0] );
+            
+            Map junitOptions = new HashMap();
+            for (Iterator it = this.options.keySet().iterator(); it.hasNext();) {
+                Object key = it.next();
+                junitOptions.put( key, options.get( key ) );
+            }
+            
+            junitOptions.put( "junit", Boolean.TRUE );
+            
+            TestNGExecutor.run( testClasses, this.testSourceDirectory, junitOptions, this.version,
this.classifier,
+                                reporterManager, this, junitReportsDirectory );
+        }
+        
+        finishTestSuite( reporterManager, this );
+    }
+
+    public static void startTestSuite( ReporterManager reporterManager, Object suite )
+    {
+        String rawString = bundle.getString( "testSetStarting" );
+
+        ReportEntry report = new ReportEntry( suite, "TestSuite", rawString );
+
+        try
+        {
+            reporterManager.testSetStarting( report );
+        }
+        catch ( ReporterException e )
+        {
+            // TODO: remove this exception from the report manager
+        }
+    }
+    
+    public static void finishTestSuite( ReporterManager reporterManager, Object suite )
+    {
+        String rawString = bundle.getString( "testSetCompletedNormally" );
+
+        ReportEntry report =
+            new ReportEntry( suite, "TestSuite", rawString );
+
+        reporterManager.testSetCompleted( report );
+
+        reporterManager.reset();
     }
 }

Modified: maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java?rev=598205&r1=598204&r2=598205&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java
Mon Nov 26 02:19:50 2007
@@ -141,36 +141,12 @@
 
     public void onStart( ISuite suite )
     {
-        String rawString = bundle.getString( "testSetStarting" );
         
-        String[] includedGroups = (String[]) suite.getMethodsByGroups().keySet().toArray(
new String[0] );
-
-        String group = groupString( includedGroups, suite.getName() );
-
-        ReportEntry report = new ReportEntry( source, suite.getName(), group, rawString );
-
-        try
-        {
-            reportManager.testSetStarting( report );
-        }
-        catch ( ReporterException e )
-        {
-            // TODO: remove this exception from the report manager
-        }
     }
     
     public void onFinish( ISuite suite )
     {
-        String rawString = bundle.getString( "testSetCompletedNormally" );
-
-        String[] includedGroups = (String[]) suite.getMethodsByGroups().keySet().toArray(
new String[0] );
-        
-        ReportEntry report =
-            new ReportEntry( source, suite.getName(), groupString( includedGroups, null ),
rawString );
-
-        reportManager.testSetCompleted( report );
 
-        reportManager.reset();
     }
 
     /**

Modified: maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java?rev=598205&r1=598204&r2=598205&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java
Mon Nov 26 02:19:50 2007
@@ -88,9 +88,10 @@
         {
             throw new IllegalStateException( "You must call locateTestSets before calling
execute" );
         }
-
+        TestNGDirectoryTestSuite.startTestSuite( reporterManager, this );
         TestNGExecutor.run( this.suiteFilePaths, this.testSourceDirectory, this.options,
this.version, 
                             this.classifier, reporterManager, this, reportsDirectory );
+        TestNGDirectoryTestSuite.finishTestSuite( reporterManager, this );
     }
 
     public void execute( String testSetName, ReporterManager reporterManager, ClassLoader
classLoader )



Mime
View raw message