Author: dfabulich
Date: Wed Nov 21 14:33:36 2007
New Revision: 597234

URL: http://svn.apache.org/viewvc?rev=597234&view=rev
Log:
[SUREFIRE-376] [SUREFIRE-379] @AfterSuite failures were ignored, @BeforeMethod 
exceptions weren't recorded

Added:
    
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/ConfigurationAwareTestNGReporter.java
Modified:
    
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Surefire376TestNgAfterSuiteFailure.java
    
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgBeforeMethodFailure.java
    
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
    
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java

Modified: 
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Surefire376TestNgAfterSuiteFailure.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Surefire376TestNgAfterSuiteFailure.java?rev=597234&r1=597233&r2=597234&view=diff
==============================================================================
--- 
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Surefire376TestNgAfterSuiteFailure.java
 (original)
+++ 
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Surefire376TestNgAfterSuiteFailure.java
 Wed Nov 21 14:33:36 2007
@@ -26,7 +26,7 @@
         // verifier.verifyErrorFreeLog();
         verifier.resetStreams();
         
-        HelperAssertions.assertTestSuiteResults( 1, 0, 1, 0, testDir );
+        HelperAssertions.assertTestSuiteResults( 2, 0, 1, 0, testDir );
         
     }
 }

Modified: 
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgBeforeMethodFailure.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgBeforeMethodFailure.java?rev=597234&r1=597233&r2=597234&view=diff
==============================================================================
--- 
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgBeforeMethodFailure.java
 (original)
+++ 
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgBeforeMethodFailure.java
 Wed Nov 21 14:33:36 2007
@@ -22,7 +22,8 @@
 
         Verifier verifier = new Verifier( testDir.getAbsolutePath() );
         verifier.executeGoal( "test" );
-        verifier.verifyErrorFreeLog();
+        //errors are expected
+        //verifier.verifyErrorFreeLog();
         verifier.resetStreams();
         
         HelperAssertions.assertTestSuiteResults( 1, 0, 0, 1, testDir );

Added: 
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/ConfigurationAwareTestNGReporter.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/ConfigurationAwareTestNGReporter.java?rev=597234&view=auto
==============================================================================
--- 
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/ConfigurationAwareTestNGReporter.java
 (added)
+++ 
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/ConfigurationAwareTestNGReporter.java
 Wed Nov 21 14:33:36 2007
@@ -0,0 +1,41 @@
+package org.apache.maven.surefire.testng;
+
+/*
+ * 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.apache.maven.surefire.report.ReporterManager;
+import org.apache.maven.surefire.suite.SurefireTestSuite;
+import org.testng.internal.IResultListener;
+
+/** Just like TestNGReporter, but explicitly implements IResultListener; this 
interface is new in TestNG 5.5
+ * 
+ * @author Dan Fabulich
+ */
+public class ConfigurationAwareTestNGReporter
+    extends TestNGReporter
+    implements IResultListener
+{
+
+    public ConfigurationAwareTestNGReporter( ReporterManager reportManager, 
SurefireTestSuite source )
+    {
+        super( reportManager, source );
+    }
+
+}

Modified: 
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java?rev=597234&r1=597233&r2=597234&view=diff
==============================================================================
--- 
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
 (original)
+++ 
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
 Wed Nov 21 14:33:36 2007
@@ -20,6 +20,7 @@
  */
 
 import java.io.File;
+import java.lang.reflect.Constructor;
 import java.util.List;
 import java.util.Map;
 
@@ -107,7 +108,7 @@
         // turn off all TestNG output
         testNG.setVerbose( 0 );
 
-        TestNGReporter reporter = new TestNGReporter( reportManager, suite );
+        TestNGReporter reporter = createTestNGReporter( reportManager, suite );
         testNG.addListener( (Object) reporter );
         attachNonStandardReporter( testNG, "org.testng.reporters.XMLReporter" 
);
         attachNonStandardReporter( testNG, 
"org.testng.reporters.FailedReporter" );
@@ -119,6 +120,26 @@
         testNG.setOutputDirectory( reportsDirectory.getAbsolutePath() );
     }
 
+    // If we have access to IResultListener, return a 
ConfigurationAwareTestNGReporter
+    // But don't cause NoClassDefFoundErrors if it isn't available; just 
return a regular TestNGReporter instead
+    private static TestNGReporter createTestNGReporter( ReporterManager 
reportManager, SurefireTestSuite suite ) {
+        try {
+            Class.forName( "org.testng.internal.IResultListener" );
+            Class c = Class.forName( 
"org.apache.maven.surefire.testng.ConfigurationAwareTestNGReporter" );
+            try
+            {
+                Constructor ctor = c.getConstructor( new Class[] { 
ReporterManager.class, SurefireTestSuite.class } );
+                return (TestNGReporter) ctor.newInstance( new Object[] { 
reportManager, suite } );
+            }
+            catch ( Exception e )
+            {
+                throw new RuntimeException("Bug in 
ConfigurationAwareTestNGReporter", e);
+            }
+        } catch (ClassNotFoundException e) {
+            return new TestNGReporter( reportManager, suite );
+        }
+    }
+    
     private static void attachNonStandardReporter( TestNG testNG, String 
className )
     {
         try

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=597234&r1=597233&r2=597234&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
 Wed Nov 21 14:33:36 2007
@@ -19,6 +19,8 @@
  * under the License.
  */
 
+import java.util.ResourceBundle;
+
 import org.apache.maven.surefire.Surefire;
 import org.apache.maven.surefire.report.ReportEntry;
 import org.apache.maven.surefire.report.ReporterException;
@@ -31,8 +33,6 @@
 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
@@ -126,11 +126,24 @@
 
     public void onStart( ITestContext context )
     {
+        
+    }
+
+    public void onFinish( ITestContext context )
+    {
+        
+    }
+
+
+    public void onStart( ISuite suite )
+    {
         String rawString = bundle.getString( "testSetStarting" );
+        
+        String[] includedGroups = (String[]) 
suite.getMethodsByGroups().keySet().toArray( new String[0] );
 
-        String group = groupString( context.getIncludedGroups(), 
context.getName() );
+        String group = groupString( includedGroups, suite.getName() );
 
-        ReportEntry report = new ReportEntry( source, context.getName(), 
group, rawString );
+        ReportEntry report = new ReportEntry( source, suite.getName(), group, 
rawString );
 
         try
         {
@@ -141,27 +154,21 @@
             // TODO: remove this exception from the report manager
         }
     }
-
-    public void onFinish( ITestContext context )
+    
+    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, context.getName(), groupString( 
context.getIncludedGroups(), null ), rawString );
+            new ReportEntry( source, suite.getName(), groupString( 
includedGroups, null ), rawString );
 
         reportManager.testSetCompleted( report );
 
         reportManager.reset();
     }
 
-    public void onFinish( ISuite suite )
-    {
-    }
-
-    public void onStart( ISuite suite )
-    {
-    }
-
     /**
      * Creates a string out of the list of testng groups in the
      * form of <pre>"group1,group2,group3"</pre>.
@@ -190,6 +197,22 @@
             retVal = defaultValue;
         }
         return retVal;
+    }
+
+    public void onConfigurationFailure( ITestResult result )
+    {
+        onTestFailure( result );
+    }
+
+    public void onConfigurationSkip( ITestResult result )
+    {
+        onTestSkipped( result );
+    }
+
+    public void onConfigurationSuccess( ITestResult result )
+    {
+        // DGF Don't record configuration successes as separate tests
+        //onTestSuccess( result );
     }
 
 }


Reply via email to