Author: dfabulich
Date: Wed Nov 21 11:43:06 2007
New Revision: 597190
URL: http://svn.apache.org/viewvc?rev=597190&view=rev
Log:
[SUREFIRE-384] Allow TestNG to generate its native XML output
Modified:
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
maven/surefire/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportParser.java
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/HelperAssertions.java
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/TestNGExecutor.java
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java
Modified:
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java?rev=597190&r1=597189&r2=597190&view=diff
==============================================================================
---
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
(original)
+++
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
Wed Nov 21 11:43:06 2007
@@ -602,7 +602,7 @@
// TODO: properties should be passed in here too
surefireBooter.addTestSuite(
"org.apache.maven.surefire.testng.TestNGXmlTestSuite", new Object[]{
- suiteXmlFiles, testSourceDirectory.getAbsolutePath(),
testNgArtifact.getVersion()} );
+ suiteXmlFiles, testSourceDirectory.getAbsolutePath(),
testNgArtifact.getVersion(), reportsDirectory} );
}
else
{
@@ -656,7 +656,7 @@
{
surefireBooter.addTestSuite(
"org.apache.maven.surefire.testng.TestNGDirectoryTestSuite", new Object[] {
testClassesDirectory, includes, excludes,
testSourceDirectory.getAbsolutePath(),
- testNgArtifact.getVersion(), properties} );
+ testNgArtifact.getVersion(), properties, reportsDirectory}
);
}
else
{
Modified:
maven/surefire/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportParser.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportParser.java?rev=597190&r1=597189&r2=597190&view=diff
==============================================================================
---
maven/surefire/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportParser.java
(original)
+++
maven/surefire/trunk/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportParser.java
Wed Nov 21 11:43:06 2007
@@ -63,7 +63,7 @@
{
if ( reportsDirectory.exists() )
{
- String[] xmlReportFiles = getIncludedFiles( reportsDirectory,
"*.xml", "*.txt" );
+ String[] xmlReportFiles = getIncludedFiles( reportsDirectory,
"*.xml", "*.txt, testng-failed.xml, testng-results.xml" );
for ( int index = 0; index < xmlReportFiles.length; index++ )
{
Modified:
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/HelperAssertions.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/HelperAssertions.java?rev=597190&r1=597189&r2=597190&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/HelperAssertions.java
(original)
+++
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/HelperAssertions.java
Wed Nov 21 11:43:06 2007
@@ -33,7 +33,12 @@
File reportsDir = new File( testDir, "target/surefire-reports" );
Assert.assertTrue( "Reports directory is missing: " +
reportsDir.getAbsolutePath(), reportsDir.exists() );
parser.setReportsDirectory( reportsDir );
- List reports = parser.parseXMLReportFiles();
+ List reports;
+ try {
+ reports = parser.parseXMLReportFiles();
+ } catch (Exception e) {
+ throw new RuntimeException("Couldn't parse XML reports: " +
reportsDir.getAbsolutePath(), e);
+ }
Assert.assertTrue( "No reports!", reports.size() > 0 );
ReportTestSuite suite = (ReportTestSuite) reports.get( 0 );
return suite;
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=597190&r1=597189&r2=597190&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
Wed Nov 21 11:43:06 2007
@@ -48,22 +48,25 @@
private Map options;
private String testSourceDirectory;
+
+ private File reportsDirectory;
public TestNGDirectoryTestSuite( File basedir, ArrayList includes,
ArrayList excludes, String testSourceDirectory,
- String artifactVersion, Properties
confOptions )
+ String artifactVersion, Properties
confOptions, File reportsDirectory )
{
this( basedir, includes, excludes, testSourceDirectory, new
DefaultArtifactVersion( artifactVersion ),
- confOptions );
+ confOptions, reportsDirectory );
}
public TestNGDirectoryTestSuite( File basedir, List includes, List
excludes, String testSourceDirectory,
- ArtifactVersion artifactVersion, Map
confOptions )
+ ArtifactVersion artifactVersion, Map
confOptions, File reportsDirectory )
{
super( basedir, includes, excludes );
this.options = confOptions;
this.testSourceDirectory = testSourceDirectory;
this.version = artifactVersion;
+ this.reportsDirectory = reportsDirectory;
}
protected SurefireTestSet createTestSet( Class testClass, ClassLoader
classLoader )
@@ -87,7 +90,7 @@
}
TestNGExecutor.run( new Class[]{testSet.getTestClass()},
this.testSourceDirectory, this.options, this.version,
- reporterManager, this );
+ reporterManager, this, reportsDirectory );
}
public void execute( ReporterManager reporterManager, ClassLoader
classLoader )
@@ -106,6 +109,6 @@
testClasses[i++] = testSet.getTestClass();
}
- TestNGExecutor.run( testClasses, this.testSourceDirectory,
this.options, this.version, reporterManager, this );
+ TestNGExecutor.run( testClasses, this.testSourceDirectory,
this.options, this.version, reporterManager, this, reportsDirectory );
}
}
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=597190&r1=597189&r2=597190&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 11:43:06 2007
@@ -19,6 +19,10 @@
* under the License.
*/
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
import org.apache.maven.artifact.versioning.ArtifactVersion;
import
org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
@@ -29,11 +33,9 @@
import org.apache.maven.surefire.testng.conf.TestNG52Configurator;
import org.apache.maven.surefire.testng.conf.TestNGMapConfigurator;
import org.apache.maven.surefire.util.NestedRuntimeException;
+import org.testng.IReporter;
import org.testng.TestNG;
-import java.util.List;
-import java.util.Map;
-
/**
* Contains utility methods for executing TestNG.
*
@@ -47,24 +49,24 @@
}
public static void run( Class[] testClasses, String testSourceDirectory,
Map options, ArtifactVersion version,
- ReporterManager reportManager, SurefireTestSuite
suite )
+ ReporterManager reportManager, SurefireTestSuite
suite, File reportsDirectory )
{
TestNG testng = new TestNG( false );
Configurator configurator = getConfigurator( version );
configurator.configure( testng, options );
- postConfigure( testng, testSourceDirectory, reportManager, suite );
+ postConfigure( testng, testSourceDirectory, reportManager, suite,
reportsDirectory );
testng.setTestClasses( testClasses );
testng.run();
}
public static void run( List suiteFiles, String testSourceDirectory, Map
options, ArtifactVersion version,
- ReporterManager reportManager, SurefireTestSuite
suite )
+ ReporterManager reportManager, SurefireTestSuite
suite, File reportsDirectory )
{
TestNG testng = new TestNG( false );
Configurator configurator = getConfigurator( version );
configurator.configure( testng, options );
- postConfigure( testng, testSourceDirectory, reportManager, suite );
+ postConfigure( testng, testSourceDirectory, reportManager, suite,
reportsDirectory );
testng.setTestSuites( suiteFiles );
testng.run();
@@ -100,20 +102,33 @@
private static void postConfigure( TestNG testNG, String sourcePath,
ReporterManager reportManager,
- SurefireTestSuite suite )
+ SurefireTestSuite suite, File
reportsDirectory )
{
// turn off all TestNG output
testNG.setVerbose( 0 );
TestNGReporter reporter = new TestNGReporter( reportManager, suite );
testNG.addListener( (Object) reporter );
+ attachNonStandardReporter( testNG, "org.testng.reporters.XMLReporter"
);
+ attachNonStandardReporter( testNG,
"org.testng.reporters.FailedReporter" );
// TODO: we should have the Profile so that we can decide if this is
needed or not
if ( sourcePath != null )
{
testNG.setSourcePath( sourcePath );
}
- // workaround for SUREFIRE-49
- // TestNG always creates an output directory, and if not set the name
for the directory is "null"
- testNG.setOutputDirectory( System.getProperty( "java.io.tmpdir" ) );
+ testNG.setOutputDirectory( reportsDirectory.getAbsolutePath() );
+ }
+
+ private static void attachNonStandardReporter( TestNG testNG, String
className )
+ {
+ try
+ {
+ Class c = Class.forName( className );
+ if (IReporter.class.isAssignableFrom( c )) {
+ testNG.addListener( c.newInstance() );
+ }
+ }
+ catch ( Exception e ) {} // ignore
}
+
}
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=597190&r1=597189&r2=597190&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
Wed Nov 21 11:43:06 2007
@@ -51,6 +51,8 @@
private ArtifactVersion version;
private Map options = new HashMap();
+
+ private File reportsDirectory;
// Not really used
private Map testSets;
@@ -59,13 +61,15 @@
* Creates a testng testset to be configured by the specified
* xml file.
*/
- public TestNGXmlTestSuite( File[] suiteFiles, String testSourceDirectory,
String artifactVersion )
+ public TestNGXmlTestSuite( File[] suiteFiles, String testSourceDirectory,
String artifactVersion, File reportsDirectory )
{
this.suiteFiles = suiteFiles;
this.version = new DefaultArtifactVersion( artifactVersion );
this.testSourceDirectory = testSourceDirectory;
+
+ this.reportsDirectory = reportsDirectory;
}
public void execute( ReporterManager reporterManager, ClassLoader
classLoader )
@@ -76,7 +80,7 @@
}
TestNGExecutor.run( this.suiteFilePaths, this.testSourceDirectory,
this.options, this.version, reporterManager,
- this );
+ this, reportsDirectory );
}
public void execute( String testSetName, ReporterManager reporterManager,
ClassLoader classLoader )