Updated Branches: refs/heads/master fc9edf9aa -> 50912ac6f
[SUREFIRE-1012] Fix runOrder for TestNG by passing the classes to test as XmlSuites o Extending the integration tests to check for runOrder with different TestNG versions Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/50912ac6 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/50912ac6 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/50912ac6 Branch: refs/heads/master Commit: 50912ac6f0dae8d9dec0a7c7638f24addc7336b7 Parents: fc9edf9 Author: Andreas Gudian <[email protected]> Authored: Wed Jul 10 00:11:09 2013 +0200 Committer: Andreas Gudian <[email protected]> Committed: Wed Jul 10 00:11:09 2013 +0200 ---------------------------------------------------------------------- .../surefire/its/CheckTestNgReportTestIT.java | 2 +- .../surefire/its/CheckTestNgVersionsIT.java | 96 +++++++++++--------- .../testng-group-thread-parallel/pom.xml | 1 + .../testng/groupThreadParallel/TestNGTest.java | 22 +++-- .../src/test/resources/testng-simple/pom.xml | 3 + .../java/testng/simple/TestNGSuiteTest.java | 13 --- .../java/testng/simple/TestNGSuiteTestA.java | 13 +++ .../java/testng/simple/TestNGSuiteTestB.java | 13 +++ .../java/testng/simple/TestNGSuiteTestC.java | 13 +++ .../maven/surefire/testng/TestNGExecutor.java | 88 +++++++++++++----- .../testng/conf/AbstractDirectConfigurator.java | 38 +++++++- .../surefire/testng/conf/Configurator.java | 6 +- .../testng/conf/TestNGMapConfigurator.java | 16 +++- 13 files changed, 231 insertions(+), 93 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/50912ac6/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgReportTestIT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgReportTestIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgReportTestIT.java index 6453003..ff6ee58 100644 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgReportTestIT.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgReportTestIT.java @@ -36,7 +36,7 @@ public class CheckTestNgReportTestIT throws Exception { final OutputValidator outputValidator = - unpack( "/testng-simple" ).addSurefireReportGoal().executeCurrentGoals().verifyErrorFree( 1 ); + unpack( "/testng-simple" ).addSurefireReportGoal().executeCurrentGoals().verifyErrorFree( 3 ); outputValidator.getSiteFile( "surefire-report.html" ).assertFileExists(); } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/50912ac6/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgVersionsIT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgVersionsIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgVersionsIT.java index 025b455..e8a9490 100644 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgVersionsIT.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgVersionsIT.java @@ -19,16 +19,24 @@ package org.apache.maven.surefire.its; * under the License. */ +import java.io.File; +import java.util.List; + +import org.apache.maven.plugins.surefire.report.ReportTestSuite; +import org.apache.maven.surefire.its.fixture.HelperAssertions; import org.apache.maven.surefire.its.fixture.OutputValidator; import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; import org.junit.Ignore; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** - * Basic suite test using all known versions of TestNG. Used for regression testing Surefire against old versions. - * To check new versions of TestNG work with current versions of Surefire, instead run the full test suite with + * Basic suite test using all known versions of TestNG. Used for regression testing Surefire against old versions. To + * check new versions of TestNG work with current versions of Surefire, instead run the full test suite with * -Dtestng.version=5.14.2 (for example) - * + * * @author <a href="mailto:[email protected]">Dan Fabulich</a> * @author <a href="mailto:[email protected]">Kristian Rosenvold</a> */ @@ -36,146 +44,146 @@ public class CheckTestNgVersionsIT extends SurefireJUnit4IntegrationTestCase { - @Test - public void test47() + @Test public void test47() throws Exception { runTestNgTest( "4.7" ); } - @Test - @Ignore("5.0 and 5.0.1 jars on central are malformed SUREFIRE-375 + MAVENUPLOAD-1024") - public void XXXtest50() + @Test @Ignore( "5.0 and 5.0.1 jars on central are malformed SUREFIRE-375 + MAVENUPLOAD-1024" ) public void XXXtest50() throws Exception { runTestNgTest( "5.0" ); } - @Test - @Ignore("5.0 and 5.0.1 jars on central are malformed SUREFIRE-375 + MAVENUPLOAD-1024") - public void XXXtest501() + @Test @Ignore( "5.0 and 5.0.1 jars on central are malformed SUREFIRE-375 + MAVENUPLOAD-1024" ) public void XXXtest501() throws Exception { runTestNgTest( "5.0.1" ); } - @Test - public void test502() + @Test public void test502() throws Exception { runTestNgTest( "5.0.2" ); } - @Test - public void test51() + @Test public void test51() throws Exception { runTestNgTest( "5.1" ); } - @Test - public void test55() + @Test public void test55() throws Exception { runTestNgTest( "5.5" ); } - @Test - public void test56() + @Test public void test56() throws Exception { runTestNgTest( "5.6" ); } - @Test - public void test57() + @Test public void test57() throws Exception { runTestNgTest( "5.7" ); } - @Test - public void test58() + @Test public void test58() throws Exception { runTestNgTest( "5.8" ); } - @Test - public void test59() + @Test public void test59() throws Exception { runTestNgTest( "5.9" ); } - @Test - public void test510() + @Test public void test510() throws Exception { runTestNgTest( "5.10" ); } - @Test - public void test511() + @Test public void test511() throws Exception { runTestNgTest( "5.11" ); } - @Test - public void test512() + @Test public void test512() throws Exception { runTestNgTest( "5.12.1" ); } - @Test - public void test513() + @Test public void test513() throws Exception { runTestNgTest( "5.13" ); } - @Test - public void test5131() + @Test public void test5131() throws Exception { runTestNgTest( "5.13.1" ); } - @Test - public void test514() + @Test public void test514() throws Exception { runTestNgTest( "5.14" ); } - @Test - public void test5141() + @Test public void test5141() throws Exception { runTestNgTest( "5.14.1" ); } - @Test - public void test5142() + @Test public void test5142() throws Exception { runTestNgTest( "5.14.2" ); } - @Test - public void test60() + @Test public void test60() throws Exception { runTestNgTest( "6.0" ); } + @Test public void test685() + throws Exception + { + runTestNgTest( "6.8.5" ); + } + public void runTestNgTest( String version ) throws Exception { final OutputValidator outputValidator = unpack( "testng-simple" ).resetInitialGoals( version ).executeTest(); - outputValidator.verifyErrorFreeLog().assertTestSuiteResults( 1, 0, 0, 0 ); + outputValidator.verifyErrorFreeLog().assertTestSuiteResults( 3, 0, 0, 0 ); + + // assert correct run order of tests + List<ReportTestSuite> report = HelperAssertions.extractReports( new File[] { outputValidator.getBaseDir() } ); + + + assertEquals( 3, report.size() ); + + assertTrue( "TestNGSuiteTestC was executed first", getTestClass( report, 0 ).endsWith( "TestNGSuiteTestC" ) ); + assertTrue( "TestNGSuiteTestB was executed second", getTestClass( report, 1 ).endsWith( "TestNGSuiteTestB" ) ); + assertTrue( "TestNGSuiteTestA was executed last", getTestClass( report, 2 ).endsWith( "TestNGSuiteTestA" ) ); + } + + private String getTestClass( List<ReportTestSuite> report, int i ) + { + return report.get( i ).getFullClassName(); } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/50912ac6/surefire-integration-tests/src/test/resources/testng-group-thread-parallel/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/testng-group-thread-parallel/pom.xml b/surefire-integration-tests/src/test/resources/testng-group-thread-parallel/pom.xml index e90aa05..2c22ab3 100644 --- a/surefire-integration-tests/src/test/resources/testng-group-thread-parallel/pom.xml +++ b/surefire-integration-tests/src/test/resources/testng-group-thread-parallel/pom.xml @@ -73,6 +73,7 @@ <groups>nonexistent, functional</groups> <threadCount>3</threadCount> <parallel>methods</parallel> + <forkCount>0</forkCount> </configuration> </plugin> <plugin> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/50912ac6/surefire-integration-tests/src/test/resources/testng-group-thread-parallel/src/test/java/testng/groupThreadParallel/TestNGTest.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/testng-group-thread-parallel/src/test/java/testng/groupThreadParallel/TestNGTest.java b/surefire-integration-tests/src/test/resources/testng-group-thread-parallel/src/test/java/testng/groupThreadParallel/TestNGTest.java index 3228847..68a4baf 100644 --- a/surefire-integration-tests/src/test/resources/testng-group-thread-parallel/src/test/java/testng/groupThreadParallel/TestNGTest.java +++ b/surefire-integration-tests/src/test/resources/testng-group-thread-parallel/src/test/java/testng/groupThreadParallel/TestNGTest.java @@ -13,7 +13,7 @@ import org.testng.annotations.Test; public class TestNGTest { - static int m_testCount = 0; + private static volatile int m_testCount = 0; /** * Sets up testObject @@ -28,7 +28,7 @@ public class TestNGTest public void check_Test_Count() { System.out.println( "check_Test_Count(): " + m_testCount ); - Assert.assertTrue( m_testCount == 3, "Expected 3 tests to be run but local count was " + m_testCount ); + Assert.assertEquals( m_testCount, 3 ); } Object testObject; @@ -37,13 +37,19 @@ public class TestNGTest public void test1() throws InterruptedException { + doTest( "test1" ); + } + + private void doTest( String test ) + throws InterruptedException + { incrementTestCount(); - System.out.println( "running test" ); - Assert.assertTrue( testObject != null, "testObject is null" ); + System.out.println( "running " + test ); + Assert.assertNotNull( testObject, "testObject" ); waitForTestCountToBeThree(); } - private synchronized void incrementTestCount() + private static synchronized void incrementTestCount() { m_testCount++; } @@ -52,14 +58,14 @@ public class TestNGTest public void test2() throws InterruptedException { - test1(); + doTest( "test2" ); } @Test( groups = { "functional", "notincluded" } ) public void test3() throws InterruptedException { - test1(); + doTest( "test3" ); } private void waitForTestCountToBeThree() @@ -74,7 +80,7 @@ public class TestNGTest { Thread.sleep( 10 ); } - Assert.assertTrue( m_testCount >= 3 ); + Assert.assertTrue( m_testCount >= 3, "Expected TestCount >= 3, but was: " + m_testCount ); } /** http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/50912ac6/surefire-integration-tests/src/test/resources/testng-simple/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/testng-simple/pom.xml b/surefire-integration-tests/src/test/resources/testng-simple/pom.xml index 3712728..d85d82f 100644 --- a/surefire-integration-tests/src/test/resources/testng-simple/pom.xml +++ b/surefire-integration-tests/src/test/resources/testng-simple/pom.xml @@ -91,6 +91,9 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>${surefire.version}</version> + <configuration> + <runOrder>reversealphabetical</runOrder> + </configuration> </plugin> </plugins> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/50912ac6/surefire-integration-tests/src/test/resources/testng-simple/src/test/java/testng/simple/TestNGSuiteTest.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/testng-simple/src/test/java/testng/simple/TestNGSuiteTest.java b/surefire-integration-tests/src/test/resources/testng-simple/src/test/java/testng/simple/TestNGSuiteTest.java deleted file mode 100644 index 5b6e1df..0000000 --- a/surefire-integration-tests/src/test/resources/testng-simple/src/test/java/testng/simple/TestNGSuiteTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package testng.simple; - -import org.testng.annotations.Test; - - -public class TestNGSuiteTest { - - @Test - public void doNothing() - { - - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/50912ac6/surefire-integration-tests/src/test/resources/testng-simple/src/test/java/testng/simple/TestNGSuiteTestA.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/testng-simple/src/test/java/testng/simple/TestNGSuiteTestA.java b/surefire-integration-tests/src/test/resources/testng-simple/src/test/java/testng/simple/TestNGSuiteTestA.java new file mode 100644 index 0000000..1dc09d7 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/testng-simple/src/test/java/testng/simple/TestNGSuiteTestA.java @@ -0,0 +1,13 @@ +package testng.simple; + +import org.testng.annotations.Test; + + +public class TestNGSuiteTestA { + + @Test + public void doNothing() + { + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/50912ac6/surefire-integration-tests/src/test/resources/testng-simple/src/test/java/testng/simple/TestNGSuiteTestB.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/testng-simple/src/test/java/testng/simple/TestNGSuiteTestB.java b/surefire-integration-tests/src/test/resources/testng-simple/src/test/java/testng/simple/TestNGSuiteTestB.java new file mode 100644 index 0000000..fe35448 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/testng-simple/src/test/java/testng/simple/TestNGSuiteTestB.java @@ -0,0 +1,13 @@ +package testng.simple; + +import org.testng.annotations.Test; + + +public class TestNGSuiteTestB { + + @Test + public void doNothing() + { + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/50912ac6/surefire-integration-tests/src/test/resources/testng-simple/src/test/java/testng/simple/TestNGSuiteTestC.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/testng-simple/src/test/java/testng/simple/TestNGSuiteTestC.java b/surefire-integration-tests/src/test/resources/testng-simple/src/test/java/testng/simple/TestNGSuiteTestC.java new file mode 100644 index 0000000..1ce8854 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/testng-simple/src/test/java/testng/simple/TestNGSuiteTestC.java @@ -0,0 +1,13 @@ +package testng.simple; + +import org.testng.annotations.Test; + + +public class TestNGSuiteTestC { + + @Test + public void doNothing() + { + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/50912ac6/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java index d4a6ac8..9d8c4dd 100644 --- a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java +++ b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java @@ -26,11 +26,17 @@ import org.apache.maven.surefire.testset.TestSetFailedException; import org.apache.maven.surefire.util.NestedRuntimeException; import org.apache.maven.surefire.util.internal.StringUtils; import org.testng.TestNG; +import org.testng.xml.XmlClass; +import org.testng.xml.XmlMethodSelector; +import org.testng.xml.XmlSuite; +import org.testng.xml.XmlTest; import java.io.File; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -43,7 +49,6 @@ import java.util.Map; public class TestNGExecutor { - private TestNGExecutor() { // noop @@ -55,32 +60,60 @@ public class TestNGExecutor { TestNG testng = new TestNG( true ); - applyGroupMatching( testng, options ); - if ( !StringUtils.isBlank( methodNamePattern ) ) + Configurator configurator = getConfigurator( (String) options.get( "testng.configurator" ) ); + System.out.println( "Configuring TestNG with: " + configurator.getClass().getSimpleName() ); + + XmlMethodSelector groupMatchingSelector = getGroupMatchingSelector( options ); + XmlMethodSelector methodNameFilteringSelector = getMethodNameFilteringSelector( methodNamePattern ); + + List<XmlSuite> suites = new ArrayList<XmlSuite>( testClasses.length ); + for ( Class testClass : testClasses ) { - applyMethodNameFiltering( testng, methodNamePattern ); + XmlSuite xmlSuite = new XmlSuite(); + + xmlSuite.setName( testClass.getName() ); + configurator.configure( xmlSuite, options ); + + XmlTest xmlTest = new XmlTest( xmlSuite ); + xmlTest.setXmlClasses( Arrays.asList( new XmlClass( testClass ) ) ); + + addSelector( xmlTest, groupMatchingSelector ); + addSelector( xmlTest, methodNameFilteringSelector ); + + suites.add( xmlSuite ); } - Configurator configurator = getConfigurator( (String) options.get("testng.configurator" ) ); - System.out.println( "Configuring TestNG with: " + configurator.getClass().getSimpleName() ); + testng.setXmlSuites( suites ); + configurator.configure( testng, options ); postConfigure( testng, testSourceDirectory, reportManager, suite, reportsDirectory ); - testng.setTestClasses( testClasses ); + testng.run(); } - private static void applyMethodNameFiltering( TestNG testng, String methodNamePattern ) + private static void addSelector( XmlTest xmlTest, XmlMethodSelector selector ) + { + if ( selector != null ) + { + xmlTest.getMethodSelectors().add( selector ); + } + } + + private static XmlMethodSelector getMethodNameFilteringSelector( String methodNamePattern ) throws TestSetFailedException { + if ( StringUtils.isBlank( methodNamePattern ) ) + { + return null; + } + // the class is available in the testClassPath String clazzName = "org.apache.maven.surefire.testng.utils.MethodSelector"; - // looks to need a high value - testng.addMethodSelector( clazzName, 10000 ); try { Class clazz = Class.forName( clazzName ); - Method method = clazz.getMethod( "setMethodName", new Class[]{ String.class } ); + Method method = clazz.getMethod( "setMethodName", new Class[] { String.class } ); method.invoke( null, methodNamePattern ); } catch ( ClassNotFoundException e ) @@ -107,9 +140,17 @@ public class TestNGExecutor { throw new TestSetFailedException( e.getMessage(), e ); } + + XmlMethodSelector xms = new XmlMethodSelector(); + + xms.setName( clazzName ); + // looks to need a high value + xms.setPriority( 10000 ); + + return xms; } - private static void applyGroupMatching( TestNG testng, Map options ) + private static XmlMethodSelector getGroupMatchingSelector( Map options ) throws TestSetFailedException { String groups = (String) options.get( ProviderParameterNames.TESTNG_GROUPS_PROP ); @@ -117,19 +158,17 @@ public class TestNGExecutor if ( groups == null && excludedGroups == null ) { - return; + return null; } // the class is available in the testClassPath String clazzName = "org.apache.maven.surefire.testng.utils.GroupMatcherMethodSelector"; - // looks to need a high value - testng.addMethodSelector( clazzName, 9999 ); try { Class clazz = Class.forName( clazzName ); // HORRIBLE hack, but TNG doesn't allow us to setup a method selector instance directly. - Method method = clazz.getMethod( "setGroups", new Class[]{ String.class, String.class } ); + Method method = clazz.getMethod( "setGroups", new Class[] { String.class, String.class } ); method.invoke( null, groups, excludedGroups ); } catch ( ClassNotFoundException e ) @@ -156,14 +195,22 @@ public class TestNGExecutor { throw new TestSetFailedException( e.getMessage(), e ); } + + XmlMethodSelector xms = new XmlMethodSelector(); + + xms.setName( clazzName ); + // looks to need a high value + xms.setPriority( 9999 ); + + return xms; } - public static void run( List<String> suiteFiles, String testSourceDirectory, Map options, RunListener reportManager, - TestNgTestSuite suite, File reportsDirectory ) + public static void run( List<String> suiteFiles, String testSourceDirectory, Map options, + RunListener reportManager, TestNgTestSuite suite, File reportsDirectory ) throws TestSetFailedException { TestNG testng = new TestNG( true ); - Configurator configurator = getConfigurator( (String) options.get("testng.configurator" ) ); + Configurator configurator = getConfigurator( (String) options.get( "testng.configurator" ) ); configurator.configure( testng, options ); postConfigure( testng, testSourceDirectory, reportManager, suite, reportsDirectory ); testng.setTestSuites( suiteFiles ); @@ -190,7 +237,6 @@ public class TestNGExecutor } } - private static void postConfigure( TestNG testNG, String sourcePath, RunListener reportManager, TestNgTestSuite suite, File reportsDirectory ) throws TestSetFailedException @@ -220,7 +266,7 @@ public class TestNGExecutor Class c = Class.forName( "org.apache.maven.surefire.testng.ConfigurationAwareTestNGReporter" ); try { - Constructor ctor = c.getConstructor( new Class[]{ RunListener.class, TestNgTestSuite.class } ); + Constructor ctor = c.getConstructor( new Class[] { RunListener.class, TestNgTestSuite.class } ); return (TestNGReporter) ctor.newInstance( reportManager, suite ); } catch ( Exception e ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/50912ac6/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/AbstractDirectConfigurator.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/AbstractDirectConfigurator.java b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/AbstractDirectConfigurator.java index b81e605..e457da8 100644 --- a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/AbstractDirectConfigurator.java +++ b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/AbstractDirectConfigurator.java @@ -25,11 +25,12 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; + import org.apache.maven.surefire.booter.ProviderParameterNames; import org.apache.maven.surefire.testset.TestSetFailedException; import org.apache.maven.surefire.util.NestedRuntimeException; - import org.testng.TestNG; +import org.testng.xml.XmlSuite; public abstract class AbstractDirectConfigurator implements Configurator @@ -57,6 +58,37 @@ public abstract class AbstractDirectConfigurator // DGF In 4.7, default listeners dump XML files in the surefire-reports directory, // confusing the report plugin. This was fixed in later versions. testng.setUseDefaultListeners( false ); + configureInstance( testng, options ); + // TODO: we should have the Profile so that we can decide if this is needed or not + testng.setListenerClasses( loadListenerClasses( listeners ) ); + } + + public void configure( XmlSuite suite, Map options ) + throws TestSetFailedException + { + Map filtered = filterForSuite( options ); + configureInstance( suite, filtered ); + } + + + protected Map filterForSuite( Map options ) + { + Map result = new HashMap(); + addPropIfNotNull( options, result, ProviderParameterNames.PARALLEL_PROP ); + addPropIfNotNull( options, result, ProviderParameterNames.THREADCOUNT_PROP ); + return result; + } + + private void addPropIfNotNull( Map options, Map result, String prop ) + { + if ( options.containsKey( prop ) ) + { + result.put( prop, options.get( prop ) ); + } + } + + private void configureInstance( Object testngInstance, Map options ) + { for ( Iterator it = options.entrySet().iterator(); it.hasNext(); ) { Map.Entry entry = (Map.Entry) it.next(); @@ -68,7 +100,7 @@ public abstract class AbstractDirectConfigurator { try { - setter.invoke( testng, val ); + setter.invoke( testngInstance, val ); } catch ( Exception ex ) { @@ -77,8 +109,6 @@ public abstract class AbstractDirectConfigurator } } - // TODO: we should have the Profile so that we can decide if this is needed or not - testng.setListenerClasses( loadListenerClasses( listeners ) ); } public static List loadListenerClasses( String listenerClasses ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/50912ac6/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/Configurator.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/Configurator.java b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/Configurator.java index 7af9db9..3019d3d 100644 --- a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/Configurator.java +++ b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/Configurator.java @@ -20,12 +20,16 @@ package org.apache.maven.surefire.testng.conf; */ import java.util.Map; -import org.apache.maven.surefire.testset.TestSetFailedException; +import org.apache.maven.surefire.testset.TestSetFailedException; import org.testng.TestNG; +import org.testng.xml.XmlSuite; public interface Configurator { void configure( TestNG testng, Map options ) throws TestSetFailedException; + + void configure ( XmlSuite suite, Map options ) + throws TestSetFailedException; } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/50912ac6/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java index 69ad244..fc06989 100755 --- a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java +++ b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java @@ -24,10 +24,11 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Map; + import org.apache.maven.surefire.booter.ProviderParameterNames; import org.apache.maven.surefire.testset.TestSetFailedException; - import org.testng.TestNG; +import org.testng.xml.XmlSuite; /** * TestNG configurator for 5.3+ versions. TestNG exposes a {@link org.testng.TestNG#configure(java.util.Map)} method. @@ -52,6 +53,19 @@ public class TestNGMapConfigurator testng.configure( convertedOptions ); } + public void configure( XmlSuite suite, Map options ) + throws TestSetFailedException + { + String threadCountString = (String) options.get( ProviderParameterNames.THREADCOUNT_PROP ); + int threadCount = ( null != threadCountString ) ? Integer.parseInt( threadCountString ) : 1; + suite.setThreadCount( threadCount ); + + String parallel = (String) options.get( ProviderParameterNames.PARALLEL_PROP ); + if ( parallel != null ) { + suite.setParallel( parallel ); + } + } + Map getConvertedOptions( Map options ) throws TestSetFailedException {
