Repository: maven-surefire Updated Branches: refs/heads/master cac940520 -> 11894397c
[SUREFIRE-1211] surefire-testng runs JUnit tests Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/11894397 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/11894397 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/11894397 Branch: refs/heads/master Commit: 11894397cee63917b3d503b424a15958e44960fb Parents: cac9405 Author: Tibor17 <[email protected]> Authored: Wed Dec 23 17:51:29 2015 +0100 Committer: Tibor17 <[email protected]> Committed: Wed Dec 23 17:51:29 2015 +0100 ---------------------------------------------------------------------- .../src/site/apt/examples/testng.apt.vm | 40 ++++++++++ .../its/jiras/Surefire1211JUnitTestNgIT.java | 1 + .../src/test/resources/surefire-1211/pom.xml | 79 ++++++++++++++++++++ .../src/test/java/jira1211/JUnitTest.java | 31 ++++++++ .../src/test/java/jira1211/TestNGSuiteTest.java | 32 ++++++++ .../testng/TestNGDirectoryTestSuite.java | 8 +- 6 files changed, 190 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/11894397/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 765e564..4921521 100644 --- a/maven-surefire-plugin/src/site/apt/examples/testng.apt.vm +++ b/maven-surefire-plugin/src/site/apt/examples/testng.apt.vm @@ -452,3 +452,43 @@ Using TestNG [...] </dependencies> +---+ + + You may want to run two providers, e.g. <<<surefire-junit47>>> and <<<surefire-testng>>>, and avoid running JUnit + tests within <<<surefire-testng>>> provider by setting property <<<junit=false>>>. + ++---+ +<plugins> + [...] + <plugin> + <groupId>${project.groupId}</groupId> + <artifactId>${project.artifactId}</artifactId> + <version>${project.version}</version> + <configuration> + [...] + <properties> + <property> + <name>junit</name> + <value>false</value> + </property> + </properties> + <threadCount>1</threadCount> + [...] + </configuration> + <dependencies> + <dependency> + <groupId>org.apache.maven.surefire</groupId> + <artifactId>surefire-junit47</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.maven.surefire</groupId> + <artifactId>surefire-testng</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </plugin> + [...] +</plugins> ++---+ + + http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/11894397/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1211JUnitTestNgIT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1211JUnitTestNgIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1211JUnitTestNgIT.java new file mode 100644 index 0000000..d75ed00 --- /dev/null +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1211JUnitTestNgIT.java @@ -0,0 +1 @@ +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.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; import org.apache.maven.surefire.its.fixture.SurefireLauncher ; import org.junit.Test; import static java.lang.System.getProperty; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.is; import static org.junit.Assume.assumeThat; /** * @author <a href="mailto:[email protected]">Tibor Digana (tibor17)</a> * @see {@linkplain https://jira.codehaus.org/browse/SUREFIRE-1211} * @since 2.19.1 */ public class Surefire1211JUnitTestNgIT extends SurefireJUnit4IntegrationTestCase { @Test public void withJUnit() { assumeThat( "java.specification.version: ", getProperty( "java.specification.version" ), is( greaterThanOrEqualTo( "1.7" ) ) ); unpack().threadCount( 1 ) .executeTest() .verifyErrorFree( 2 ); } @Test public void withoutJUnit() { assumeThat( "java.specification.version: ", getProperty( "java.specification.version" ), is( greaterThanOrEqualTo( "1.7" ) ) ); unpack().threadCount( 1 ) .sysProp( "junit", "false" ) .executeTest() .verifyErrorFree( 1 ); } private SurefireLauncher unpack() { return unpack( "surefire-1211" ); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/11894397/surefire-integration-tests/src/test/resources/surefire-1211/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-1211/pom.xml b/surefire-integration-tests/src/test/resources/surefire-1211/pom.xml new file mode 100644 index 0000000..d867b3c --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-1211/pom.xml @@ -0,0 +1,79 @@ +<?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> + </parent> + + <groupId>org.apache.maven.plugins.surefire</groupId> + <artifactId>surefire-1211</artifactId> + <version>1.0</version> + + <properties> + <junit/> + </properties> + + <dependencies> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <version>6.9.4</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.10</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.5</source> + <target>1.5</target> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <forkMode>once</forkMode> + <properties> + <property> + <name>junit</name> + <value>${junit}</value> + </property> + </properties> + </configuration> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/11894397/surefire-integration-tests/src/test/resources/surefire-1211/src/test/java/jira1211/JUnitTest.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-1211/src/test/java/jira1211/JUnitTest.java b/surefire-integration-tests/src/test/resources/surefire-1211/src/test/java/jira1211/JUnitTest.java new file mode 100644 index 0000000..1580e8a --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-1211/src/test/java/jira1211/JUnitTest.java @@ -0,0 +1,31 @@ +package jira1211; + +/* + * 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.junit.Test; + +public class JUnitTest { + + @Test + public void doNothing() + { + + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/11894397/surefire-integration-tests/src/test/resources/surefire-1211/src/test/java/jira1211/TestNGSuiteTest.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-1211/src/test/java/jira1211/TestNGSuiteTest.java b/surefire-integration-tests/src/test/resources/surefire-1211/src/test/java/jira1211/TestNGSuiteTest.java new file mode 100644 index 0000000..46959c7 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-1211/src/test/java/jira1211/TestNGSuiteTest.java @@ -0,0 +1,32 @@ +package jira1211; + +/* + * 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; + + +public class TestNGSuiteTest { + + @Test + public void doNothing() + { + + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/11894397/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java index 4e1a7f3..a695ef6 100644 --- a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java +++ b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java @@ -35,6 +35,7 @@ import org.apache.maven.surefire.testset.TestSetFailedException; import org.apache.maven.surefire.util.TestsToRun; import static org.apache.maven.surefire.testng.TestNGExecutor.run; +import static org.apache.maven.surefire.util.internal.StringUtils.isBlank; /** * Test suite for TestNG based on a directory of Java test classes. Can also execute JUnit tests. @@ -240,7 +241,12 @@ final class TestNGDirectoryTestSuite private Map<String, String> createJUnitOptions() { Map<String, String> junitOptions = new HashMap<String, String>( options ); - junitOptions.put( "junit", "true" ); + String onlyJUnit = options.get( "junit" ); + if ( isBlank( onlyJUnit ) ) + { + onlyJUnit = "true"; + } + junitOptions.put( "junit", onlyJUnit ); return junitOptions; }
