Skip to content

Commit 2cf4674

Browse files
sbabcocslawekjaranowski
authored andcommitted
[SUREFIRE-2075] Only set thread count if spec'd
1 parent 7008175 commit 2cf4674

File tree

4 files changed

+128
-4
lines changed

4 files changed

+128
-4
lines changed

surefire-its/src/test/java/org/apache/maven/surefire/its/CheckTestNg740ParallelIT.java

+8
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,12 @@ public void withTestNG740AndParallelSet()
3535
.executeTest()
3636
.assertTestSuiteResults( 2, 0, 0, 0 );
3737
}
38+
39+
@Test
40+
public void withTestNG740AndParallelSetWithoutThreadCount()
41+
{
42+
unpack( "testng-740-parallel-without-threadcount" )
43+
.executeTest()
44+
.assertTestSuiteResults( 2, 0, 0, 0 );
45+
}
3846
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
21+
<project xmlns="http://maven.apache.org/POM/4.0.0"
22+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
26+
<groupId>org.apache.maven.plugins.surefire</groupId>
27+
<artifactId>testng-740-parallel</artifactId>
28+
<version>1.0-SNAPSHOT</version>
29+
<name>TestNG 7.4.0 parallel test</name>
30+
31+
<properties>
32+
<surefire.testng.verbose>0</surefire.testng.verbose>
33+
<argLine/>
34+
<jacoco.agent/>
35+
<maven.compiler.source>1.7</maven.compiler.source>
36+
<maven.compiler.target>1.7</maven.compiler.target>
37+
</properties>
38+
39+
<build>
40+
<plugins>
41+
<plugin>
42+
<groupId>org.apache.maven.plugins</groupId>
43+
<artifactId>maven-surefire-plugin</artifactId>
44+
<version>${surefire.version}</version>
45+
<configuration>
46+
<argLine>${argLine} ${jacoco.agent}</argLine>
47+
<parallel>methods</parallel>
48+
<properties>
49+
<property>
50+
<name>surefire.testng.verbose</name>
51+
<value>${surefire.testng.verbose}</value>
52+
</property>
53+
</properties>
54+
</configuration>
55+
</plugin>
56+
</plugins>
57+
</build>
58+
<dependencies>
59+
<dependency>
60+
<groupId>org.testng</groupId>
61+
<artifactId>testng</artifactId>
62+
<version>7.4.0</version>
63+
<exclusions>
64+
<exclusion>
65+
<!-- NOTE: Deliberaty excluding junit to enforce TestNG only tests, cf. SUREFIRE-642 -->
66+
<groupId>junit</groupId>
67+
<artifactId>junit</artifactId>
68+
</exclusion>
69+
</exclusions>
70+
</dependency>
71+
</dependencies>
72+
73+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package testng.simple;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
import org.testng.annotations.Test;
23+
24+
25+
public class TestNG740ParallelTest {
26+
@Test
27+
public void testOne() {
28+
29+
}
30+
31+
@Test
32+
public void testTwo() {
33+
34+
}
35+
}

surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.testng.TestNG;
2929
import org.testng.xml.XmlSuite;
3030

31-
import static java.lang.Integer.parseInt;
3231
import static org.apache.maven.surefire.api.booter.ProviderParameterNames.PARALLEL_PROP;
3332
import static org.apache.maven.surefire.api.booter.ProviderParameterNames.THREADCOUNT_PROP;
3433
import static org.apache.maven.surefire.testng.conf.AbstractDirectConfigurator.loadListenerClasses;
@@ -68,9 +67,18 @@ public void configure( XmlSuite suite, Map<String, String> options )
6867
protected void configureThreadCount( XmlSuite suite, Map<String, String> options )
6968
throws TestSetFailedException
7069
{
71-
String threadCountAsString = options.get( THREADCOUNT_PROP );
72-
int threadCount = threadCountAsString == null ? 1 : parseInt( threadCountAsString );
73-
suite.setThreadCount( threadCount );
70+
String threadCount = options.get( THREADCOUNT_PROP );
71+
if ( threadCount != null )
72+
{
73+
try
74+
{
75+
suite.setThreadCount( Integer.parseInt( threadCount ) );
76+
}
77+
catch ( NumberFormatException e )
78+
{
79+
throw new TestSetFailedException( "Non-integer TestNG [threadcount] setting: " + threadCount, e );
80+
}
81+
}
7482
}
7583

7684
protected void configureParallel( XmlSuite suite, Map<String, String> options )

0 commit comments

Comments
 (0)