[SUREFIRE-1177] TestNG "suitethreadpoolsize" parameter can not be set by Maven Surefire
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/178e6794 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/178e6794 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/178e6794 Branch: refs/heads/master Commit: 178e67942c7f25291e0e13d187e026f7f60b4bb2 Parents: 20ff270 Author: Tibor17 <[email protected]> Authored: Mon Oct 12 08:22:26 2015 +0200 Committer: Tibor17 <[email protected]> Committed: Mon Oct 12 08:22:26 2015 +0200 ---------------------------------------------------------------------- .../src/site/apt/examples/testng.apt.vm | 26 ++++++ .../surefire/its/fixture/OutputValidator.java | 18 ++++ .../Surefire1177TestngParallelSuitesIT.java | 54 ++++++++++++ .../resources/testng-parallel-suites/pom.xml | 88 ++++++++++++++++++++ .../java/testng/suiteXml/ShouldNotRunTest.java | 35 ++++++++ .../java/testng/suiteXml/TestNGSuiteTest.java | 43 ++++++++++ .../src/test/resources/testng1.xml | 30 +++++++ .../src/test/resources/testng2.xml | 30 +++++++ .../testng/conf/TestNGMapConfigurator.java | 10 +-- 9 files changed, 326 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/178e6794/maven-surefire-plugin/src/site/apt/examples/testng.apt.vm ---------------------------------------------------------------------- diff --git a/maven-surefire-plugin/src/site/apt/examples/testng.apt.vm b/maven-surefire-plugin/src/site/apt/examples/testng.apt.vm index e9c6cde..b74bd3d 100644 --- a/maven-surefire-plugin/src/site/apt/examples/testng.apt.vm +++ b/maven-surefire-plugin/src/site/apt/examples/testng.apt.vm @@ -196,6 +196,32 @@ Using TestNG [...] </plugins> +---+ + + TestNG 6.9.7 or higher allows you to run suites in parallel. + ++---+ +</plugins> + [...] + <plugin> + <groupId>${project.groupId}</groupId> + <artifactId>${project.artifactId}</artifactId> + <version>${project.version}</version> + <configuration> + <suiteXmlFiles> + <file>src/test/resources/testng1.xml</file> + <file>src/test/resources/testng2.xml</file> + </suiteXmlFiles> + <properties> + <property> + <name>suitethreadpoolsize</name> + <value>2</value> + </property> + </properties> + </configuration> + </plugin> + [...] +</plugins> ++---+ See also {{{./fork-options-and-parallel-execution.html}Fork Options and Parallel Test Execution}}. http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/178e6794/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/OutputValidator.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/OutputValidator.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/OutputValidator.java index 6ef06b4..8184abe 100644 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/OutputValidator.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/OutputValidator.java @@ -28,6 +28,9 @@ import java.util.List; import org.apache.commons.io.FileUtils; import org.apache.maven.it.VerificationException; import org.apache.maven.it.Verifier; +import org.hamcrest.Matcher; + +import static org.hamcrest.MatcherAssert.assertThat; /** * A specialized verifier that enforces a standard use case for surefire IT's @@ -87,6 +90,21 @@ public class OutputValidator } } + public OutputValidator assertThatLogLine( Matcher<String> line, Matcher<Integer> nTimes ) + throws VerificationException + { + int counter = 0; + for ( String log : loadLogLines() ) + { + if ( line.matches( log ) ) + { + counter++; + } + } + assertThat( "log pattern does not match nTimes", counter, nTimes ); + return this; + } + public Collection<String> loadLogLines() throws VerificationException { http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/178e6794/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1177TestngParallelSuitesIT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1177TestngParallelSuitesIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1177TestngParallelSuitesIT.java new file mode 100644 index 0000000..62eef9b --- /dev/null +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1177TestngParallelSuitesIT.java @@ -0,0 +1,54 @@ +package org.apache.maven.surefire.its.jiras; + +/* + * 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.it.VerificationException; +import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; +import org.apache.maven.surefire.its.fixture.SurefireLauncher; +import org.junit.Test; + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.startsWith; + +/** + * IT for https://issues.apache.org/jira/browse/SUREFIRE-1177 + * + * @author <a href="mailto:[email protected]">Tibor Digana (tibor17)</a> + * @since 2.19 + */ +public class Surefire1177TestNGParallelSuitesIT + extends SurefireJUnit4IntegrationTestCase +{ + @Test + public void shouldRunTwoSuitesInParallel() + throws VerificationException + { + unpack().executeTest() + .verifyErrorFree( 2 ) + .assertThatLogLine( startsWith( "TestNGSuiteTest#shouldRunAndPrintItself()" ), is( 2 ) ) + .assertThatLogLine( is( "TestNGSuiteTest#shouldRunAndPrintItself() 1." ), is( 1 ) ) + .assertThatLogLine( is( "TestNGSuiteTest#shouldRunAndPrintItself() 2." ), is( 1 ) ); + } + + private SurefireLauncher unpack() + { + return unpack( "testng-parallel-suites" ); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/178e6794/surefire-integration-tests/src/test/resources/testng-parallel-suites/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/testng-parallel-suites/pom.xml b/surefire-integration-tests/src/test/resources/testng-parallel-suites/pom.xml new file mode 100644 index 0000000..f9598ab --- /dev/null +++ b/surefire-integration-tests/src/test/resources/testng-parallel-suites/pom.xml @@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.maven.surefire</groupId> + <artifactId>it-parent</artifactId> + <version>1.0</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <groupId>org.apache.maven.plugins.surefire</groupId> + <artifactId>testng-parallel-suites</artifactId> + <version>1.0</version> + + <url>http://maven.apache.org</url> + + <developers> + <developer> + <id>tibordigana</id> + <name>Tibor DigaÅa (tibor17)</name> + <email>[email protected]</email> + <roles> + <role>Committer</role> + </roles> + <timezone>Europe/Bratislava</timezone> + </developer> + </developers> + + <dependencies> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <version>6.9.7</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <suiteXmlFiles> + <file>src/test/resources/testng1.xml</file> + <file>src/test/resources/testng2.xml</file> + </suiteXmlFiles> + <properties> + <property> + <name>suitethreadpoolsize</name> + <value>2</value> + </property> + </properties> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.5</source> + <target>1.5</target> + </configuration> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/178e6794/surefire-integration-tests/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/ShouldNotRunTest.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/ShouldNotRunTest.java b/surefire-integration-tests/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/ShouldNotRunTest.java new file mode 100644 index 0000000..d2eb9ca --- /dev/null +++ b/surefire-integration-tests/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/ShouldNotRunTest.java @@ -0,0 +1,35 @@ +package testng.suiteXml; + +/* + * 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.testng.annotations.Test; + +/** + * @author <a href="mailto:[email protected]">Tibor Digana (tibor17)</a> + * @since 2.19 + */ +public class ShouldNotRunTest { + + @Test + public void shouldNotRun() + { + System.out.println( getClass().getSimpleName() + "#shouldNotRun()" ); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/178e6794/surefire-integration-tests/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/TestNGSuiteTest.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/TestNGSuiteTest.java b/surefire-integration-tests/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/TestNGSuiteTest.java new file mode 100644 index 0000000..b20e81e --- /dev/null +++ b/surefire-integration-tests/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/TestNGSuiteTest.java @@ -0,0 +1,43 @@ +package testng.suiteXml; + +/* + * 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.testng.annotations.Test; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * @author <a href="mailto:[email protected]">Tibor Digana (tibor17)</a> + * @since 2.19 + */ +public class TestNGSuiteTest { + private static final AtomicInteger counter = new AtomicInteger(); + + @Test + public void shouldRunAndPrintItself() + throws Exception + { + System.out.println( getClass().getSimpleName() + "#shouldRunAndPrintItself() " + + counter.incrementAndGet() + "."); + + TimeUnit.SECONDS.sleep( 2 ); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/178e6794/surefire-integration-tests/src/test/resources/testng-parallel-suites/src/test/resources/testng1.xml ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/testng-parallel-suites/src/test/resources/testng1.xml b/surefire-integration-tests/src/test/resources/testng-parallel-suites/src/test/resources/testng1.xml new file mode 100644 index 0000000..1655967 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/testng-parallel-suites/src/test/resources/testng1.xml @@ -0,0 +1,30 @@ +<!-- + ~ 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. + --> + +<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > + +<suite name="Suite 1 Test" verbose="4"> + + <test name="Sample Test"> + <classes> + <class name="testng.suiteXml.TestNGSuiteTest"/> + </classes> + </test> + +</suite> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/178e6794/surefire-integration-tests/src/test/resources/testng-parallel-suites/src/test/resources/testng2.xml ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/testng-parallel-suites/src/test/resources/testng2.xml b/surefire-integration-tests/src/test/resources/testng-parallel-suites/src/test/resources/testng2.xml new file mode 100644 index 0000000..3f0749a --- /dev/null +++ b/surefire-integration-tests/src/test/resources/testng-parallel-suites/src/test/resources/testng2.xml @@ -0,0 +1,30 @@ +<!-- + ~ 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. + --> + +<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > + +<suite name="Suite 2 Test" verbose="4"> + + <test name="Sample Test"> + <classes> + <class name="testng.suiteXml.TestNGSuiteTest"/> + </classes> + </test> + +</suite> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/178e6794/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 fe08810..1fa2485 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 @@ -113,20 +113,14 @@ public class TestNGMapConfigurator { val = convert ( val, String.class ); } - // TODO Add some integration tests - // Related issues: - // https://issues.apache.org/jira/browse/SUREFIRE-1177 - // https://issues.apache.org/jira/browse/SUREFIRE-1179 - // should work in TestNG 6.9.7 - // only useful in specific cases - prevents from passing string instead of integer else if ( "suitethreadpoolsize".equals( key ) ) { + // for TestNG 6.9.7 or higher val = convert( val, Integer.class ); } - // should work in TestNG 6.9.7 - // only useful in specific cases - prevents from passing string instead of integer else if ( "dataproviderthreadcount".equals( key ) ) { + // for TestNG 5.10 or higher val = convert( val, Integer.class ); } // TODO objectfactory... not even documented, does it work?
