maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r383001 - in /maven/surefire/branches/surefire-testng: surefire-api/src/main/java/org/apache/maven/surefire/suite/ surefire-api/src/main/java/org/apache/maven/surefire/testset/ surefire-providers/surefire-testng/src/main/java/org/apache/mav...
Date Sat, 04 Mar 2006 02:10:09 GMT
Author: brett
Date: Fri Mar  3 18:10:07 2006
New Revision: 383001

URL: http://svn.apache.org/viewcvs?rev=383001&view=rev
Log:
[MSUREFIRE-23] wire up TestNG properly

Modified:
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/AbstractTestSet.java
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/SurefireTestSet.java
    maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
    maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java
    maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGTestSet.java

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java?rev=383001&r1=383000&r2=383001&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
Fri Mar  3 18:10:07 2006
@@ -38,7 +38,7 @@
 public abstract class AbstractDirectoryTestSuite
     implements SurefireTestSuite
 {
-    private ResourceBundle bundle = ResourceBundle.getBundle( Surefire.SUREFIRE_BUNDLE_NAME
);
+    protected ResourceBundle bundle = ResourceBundle.getBundle( Surefire.SUREFIRE_BUNDLE_NAME
);
 
     private static final String FS = System.getProperty( "file.separator" );
 
@@ -48,7 +48,7 @@
 
     private List excludes;
 
-    private Map testSets;
+    protected Map testSets;
 
     private int totalTests;
 

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/AbstractTestSet.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/AbstractTestSet.java?rev=383001&r1=383000&r2=383001&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/AbstractTestSet.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/AbstractTestSet.java
Fri Mar  3 18:10:07 2006
@@ -56,7 +56,7 @@
         return testMethods.size();
     }
 
-    protected Class getTestClass()
+    public Class getTestClass()
     {
         return testClass;
     }

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/SurefireTestSet.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/SurefireTestSet.java?rev=383001&r1=383000&r2=383001&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/SurefireTestSet.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/SurefireTestSet.java
Fri Mar  3 18:10:07 2006
@@ -28,4 +28,5 @@
 
     String getName();
 
+    Class getTestClass();
 }

Modified: maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java?rev=383001&r1=383000&r2=383001&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
Fri Mar  3 18:10:07 2006
@@ -16,11 +16,23 @@
  * limitations under the License.
  */
 
+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 org.testng.ISuiteListener;
+import org.testng.ITestListener;
+import org.testng.TestNG;
+import org.testng.internal.annotations.IAnnotationFinder;
+import org.testng.xml.XmlClass;
+import org.testng.xml.XmlSuite;
+import org.testng.xml.XmlTest;
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
 
 /**
  * Test suite for TestNG based on a directory of Java test classes. Can also execute JUnit
tests.
@@ -30,16 +42,110 @@
 public class TestNGDirectoryTestSuite
     extends AbstractDirectoryTestSuite
 {
+    private String groups;
+
+    private String excludedGroups;
+
+    private boolean parallel;
+
+    private int threadCount;
+
+    private String testSourceDirectory;
+
+    private IAnnotationFinder annotationFinder;
+
     public TestNGDirectoryTestSuite( File basedir, ArrayList includes, ArrayList excludes,
String groups,
-                                     String excludedGroups, Boolean parallel, Integer threadCount
)
+                                     String excludedGroups, Boolean parallel, Integer threadCount,
+                                     String testSourceDirectory )
+        throws IllegalAccessException, InstantiationException, ClassNotFoundException
     {
         super( basedir, includes, excludes );
 
-        // TODO
+        this.groups = groups;
+
+        this.excludedGroups = excludedGroups;
+
+        this.parallel = parallel.booleanValue();
+
+        this.threadCount = threadCount.intValue();
+
+        this.testSourceDirectory = testSourceDirectory;
+
+        Class annotationClass;
+        try
+        {
+            annotationClass = Class.forName( "org.testng.internal.annotations.JDK15AnnotationFinder"
);
+        }
+        catch ( ClassNotFoundException e )
+        {
+            annotationClass = Class.forName( "org.testng.internal.annotations.JDK14AnnotationFinder"
);
+        }
+
+        annotationFinder = (IAnnotationFinder) annotationClass.newInstance();
     }
 
     protected SurefireTestSet createTestSet( Class testClass, ClassLoader classLoader )
     {
         return new TestNGTestSet( testClass );
+    }
+
+    public void execute( ReporterManager reporterManager, ClassLoader classLoader )
+        throws ReporterException, TestSetFailedException
+    {
+        if ( testSets == null )
+        {
+            throw new IllegalStateException( "You must call locateTestSets before calling
execute" );
+        }
+
+        XmlSuite suite = new XmlSuite();
+        // TODO: set name
+        suite.setParallel( parallel );
+        suite.setThreadCount( threadCount );
+
+        for ( Iterator i = testSets.values().iterator(); i.hasNext(); )
+        {
+            SurefireTestSet testSet = (SurefireTestSet) i.next();
+
+            XmlTest xmlTest = new XmlTest( suite );
+            xmlTest.setName( testSet.getName() );
+            // TODO: should these be grouped into a single XmlTest?
+            xmlTest.setXmlClasses( Collections.singletonList( new XmlClass( testSet.getTestClass()
) ) );
+
+/*
+            // TODO: not working, due to annotations being in a different classloader.
+            //   We could just check if it extends TestCase, but that would rule out non-TestNG
pojo handling
+            if ( !TestNGClassFinder.isTestNGClass( testSet.getTestClass(), annotationFinder
) )
+            {
+                // TODO: is this correct, or should it be a JUnitBattery?
+                xmlTest.setJUnit( true );
+            }
+*/
+        }
+
+        TestNG testNG = new TestNG();
+        // turn off all TestNG output
+        testNG.setVerbose( 0 );
+        // TODO: check these work, otherwise put them in the xmlTest instances
+        if ( groups != null )
+        {
+            testNG.setGroups( groups );
+        }
+        if ( excludedGroups != null )
+        {
+            testNG.setExcludedGroups( excludedGroups );
+        }
+        testNG.setXmlSuites( Collections.singletonList( suite ) );
+
+        TestNGReporter reporter = new TestNGReporter( reporterManager, this );
+        testNG.addListener( (ITestListener) reporter );
+        testNG.addListener( (ISuiteListener) reporter );
+
+        // Set source path so testng can find javadoc annotations if not in 1.5 jvm
+        if ( testSourceDirectory != null )
+        {
+            testNG.setSourcePath( testSourceDirectory );
+        }
+
+        testNG.runSuitesLocally();
     }
 }

Modified: maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java?rev=383001&r1=383000&r2=383001&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java
Fri Mar  3 18:10:07 2006
@@ -17,10 +17,19 @@
  */
 
 import org.apache.maven.surefire.Surefire;
+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.SurefireTestSuite;
+import org.testng.ISuite;
+import org.testng.ISuiteListener;
+import org.testng.ITestContext;
 import org.testng.ITestListener;
+import org.testng.ITestResult;
 import org.testng.TestNG;
 
+import java.util.ResourceBundle;
+
 /**
  * Listens for and provides and adaptor layer so that
  * TestNG tests can report their status to the current
@@ -29,18 +38,17 @@
  * @author jkuhnert
  */
 public class TestNGReporter
-//    implements ITestListener, ISuiteListener (TODO)
+    implements ITestListener, ISuiteListener
 {
+    // TODO: check the bundles
+    private ResourceBundle bundle = ResourceBundle.getBundle( Surefire.SUREFIRE_BUNDLE_NAME
);
 
     /**
      * core Surefire reporting
      */
     protected ReporterManager reportManager;
 
-    /**
-     * core Surefire instance
-     */
-    protected Surefire surefire;
+    private Object source;
 
     /**
      * Constructs a new instance that will listen to
@@ -51,47 +59,41 @@
      * suite is run.
      *
      * @param reportManager Instance to report suite status to
-     * @param surefire      Main instance that provides resources messages,etc.
      */
-    public TestNGReporter( ReporterManager reportManager, Surefire surefire )
+    public TestNGReporter( ReporterManager reportManager, SurefireTestSuite source )
     {
         this.reportManager = reportManager;
-        this.surefire = surefire;
 
         if ( reportManager == null )
         {
             throw new IllegalArgumentException( "ReportManager passed in was null." );
         }
-        if ( surefire == null )
-        {
-            throw new IllegalArgumentException( "Surefire passed in was null." );
-        }
+
+        this.source = source;
     }
 
-/* TODO
     public void onTestStart( ITestResult result )
     {
-        String rawString = Surefire.getResourceString( "testStarting" );
+        String rawString = bundle.getString( "testStarting" );
         String group = groupString( result.getMethod().getGroups(), result.getTestClass().getName()
);
-        ReportEntry report = new ReportEntry( surefire, result.getTestClass().getName() +
"#" +
+        ReportEntry report = new ReportEntry( source, result.getTestClass().getName() + "#"
+
             result.getMethod().getMethodName(), group, rawString );
 
         reportManager.testStarting( report );
-
-
     }
 
     public void onTestSuccess( ITestResult result )
     {
-        reportManager.testSucceeded( createReport( result, "testSuccessful" ) );
+        ReportEntry report = new ReportEntry( source, result.getName(), bundle.getString(
"testSuccessful" ) );
+        reportManager.testSucceeded( report );
     }
 
     public void onTestFailure( ITestResult result )
     {
-        String rawString = Surefire.getResourceString( "executeException" );
+        String rawString = bundle.getString( "executeException" );
 
         // TODO: almost certainly not correct: result.getMethod().getExtraOutput().getParameterOutput()
-        ReportEntry report = new ReportEntry( surefire, result.getName(),
+        ReportEntry report = new ReportEntry( source, result.getName(),
                                               rawString + result.getMethod().getExtraOutput().getParameterOutput(),
                                               result.getThrowable() );
 
@@ -100,48 +102,50 @@
 
     public void onTestSkipped( ITestResult result )
     {
-        // TODO: is this correct?
-        reportManager.testSucceeded( createReport( result, "testSkipped" ) );
-    }
+        ReportEntry report = new ReportEntry( source, result.getName(), bundle.getString(
"testSkipped" ) );
 
-    private ReportEntry createReport( ITestResult result, String key )
-    {
-        return new ReportEntry( surefire, result.getName(), Surefire.getResourceString( key
) );
+        // TODO: is this correct?
+        reportManager.testSucceeded( report );
     }
 
     public void onTestFailedButWithinSuccessPercentage( ITestResult result )
     {
-        String rawString = Surefire.getResourceString( "executeException" );
+        String rawString = bundle.getString( "executeException" );
 
         // TODO: almost certainly not correct: result.getMethod().getExtraOutput().getParameterOutput()
-        ReportEntry report = new ReportEntry( surefire, result.getName(),
-                                              rawString + result.getMethod().getExtraOutput(),
result.getThrowable() );
+        ReportEntry report = new ReportEntry( source, result.getName(), rawString + result.getMethod().getExtraOutput(),
+                                              result.getThrowable() );
 
         reportManager.testError( report );
     }
 
     public void onStart( ITestContext context )
     {
-        String rawString = Surefire.getResourceString( "suiteExecutionStarting" );
+        String rawString = bundle.getString( "testSetStarting" );
 
         String group = groupString( context.getIncludedGroups(), context.getName() );
 
-        ReportEntry report = new ReportEntry( surefire, context.getName(), group, rawString
);
+        ReportEntry report = new ReportEntry( source, context.getName(), group, rawString
);
 
-        reportManager.testSetStarting( report );
+        try
+        {
+            reportManager.testSetStarting( report );
+        }
+        catch ( ReporterException e )
+        {
+            // TODO: remove this exception from the report manager
+        }
     }
 
     public void onFinish( ITestContext context )
     {
-        String rawString = Surefire.getResourceString( "suiteCompletedNormally" );
+        String rawString = bundle.getString( "testSetCompletedNormally" );
 
         ReportEntry report =
-            new ReportEntry( surefire, context.getName(), groupString( context.getIncludedGroups(),
null ), rawString );
+            new ReportEntry( source, context.getName(), groupString( context.getIncludedGroups(),
null ), rawString );
 
         reportManager.testSetCompleted( report );
 
-        reportManager.runCompleted();
-
         reportManager.reset();
     }
 
@@ -152,7 +156,6 @@
     public void onStart( ISuite suite )
     {
     }
-*/
 
     /**
      * Creates a string out of the list of testng groups in the

Modified: maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGTestSet.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGTestSet.java?rev=383001&r1=383000&r2=383001&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGTestSet.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGTestSet.java
Fri Mar  3 18:10:07 2006
@@ -16,20 +16,11 @@
  * limitations under the License.
  */
 
-import org.apache.maven.surefire.Surefire;
 import org.apache.maven.surefire.report.ReporterManager;
 import org.apache.maven.surefire.testset.AbstractTestSet;
-import org.testng.TestNG;
-import org.testng.internal.TestNGClassFinder;
-import org.testng.internal.Utils;
-import org.testng.internal.annotations.IAnnotationFinder;
-import org.testng.internal.annotations.JDK14AnnotationFinder;
-import org.testng.internal.annotations.JDK15AnnotationFinder;
-import org.testng.xml.ClassSuite;
 
 import java.lang.reflect.Method;
 import java.util.ArrayList;
-import java.util.List;
 
 /**
  * Main plugin point for running testng tests within the Surefire runtime
@@ -40,10 +31,6 @@
 public class TestNGTestSet
     extends AbstractTestSet
 {
-    private String testSourceDirectory;
-
-    private static IAnnotationFinder annotationFinder;
-
     /**
      * Creates a new test testset that will process the class being
      * passed in to determine the testing configuration.
@@ -51,10 +38,6 @@
     public TestNGTestSet( Class testClass )
     {
         super( testClass );
-
-/*
-        this.testSourceDirectory = testSourceDirectory;
-*/
     }
 
     protected void discoverTestMethods()
@@ -87,71 +70,7 @@
 
     public void execute( ReporterManager reportManager, ClassLoader loader )
     {
-        // TODO: maybe don't execute this for every testset
-
-        TestNG testNG = new TestNG();
-        List classes = new ArrayList();
-        classes.add( getTestClass() );
-
-        String groups = null;
-
-        if ( !TestNGClassFinder.isTestNGClass( getTestClass(), getAnnotationFinder() ) )
-        {
-//            testNG.setJUnit( Boolean.TRUE );
-        }
-
-        //configure testng parameters
-        ClassSuite classSuite = new ClassSuite( groups != null ? groups : "TestNG Suite",
Utils.classesToXmlClasses(
-            (Class[]) classes.toArray( new Class[classes.size()] ) ) );
-        testNG.setCommandLineSuite( classSuite );
-        // TODO
-//        testNG.setOutputDirectory( reportManager.getReportsDirectory() );
-        Surefire surefire = new Surefire(); // TODO: blatently wrong
-        TestNGReporter testngReporter = new TestNGReporter( reportManager, surefire );
-/* TODO
-        testNG.addListener( (ITestListener) testngReporter );
-        testNG.addListener( (ISuiteListener) testngReporter );
-*/
-
-        // TODO: maybe this was running junit tests for us so that parallel would work
-//        testNG.setThreadCount( threadCount );
-//        testNG.setParallel( parallel );
-//
-//        if ( groups != null )
-//        {
-//            testNG.setGroups( groups );
-//        }
-//        if ( excludedGroups != null )
-//        {
-//            testNG.setExcludedGroups( excludedGroups );
-//        }
-
-        //set source path so testng can find javadoc
-        //annotations if not in 1.5 jvm
-        if ( /* TODO - necessary? !jvm15  && */ testSourceDirectory != null )
-        {
-            testNG.setSourcePath( testSourceDirectory );
-        }
-
-        //actually runs all the tests
-        List result = testNG.runSuitesLocally();
-//        nbTests += result.size(); TODO
-    }
-
-    private static IAnnotationFinder getAnnotationFinder()
-    {
-        // TODO: is this right? isn't it dependant on the version of the TestNG JAR being
used?
-        if ( annotationFinder == null )
-        {
-            if ( System.getProperty( "java.version" ).indexOf( "1.5" ) > -1 )
-            {
-                annotationFinder = new JDK15AnnotationFinder();
-            }
-            else
-            {
-                annotationFinder = new JDK14AnnotationFinder();
-            }
-        }
-        return annotationFinder;
+        throw new UnsupportedOperationException(
+            "This should have been called directly from TestNGDirectoryTestSuite" );
     }
 }



Mime
View raw message