[ACCEPTED]-Running single test class or group with Surefire and TestNG-surefire
I didn't test with TestNG 5.12.1 but I can 6 say that running a single test using the 5 test
parameter and tests from groups using the 4 groups
parameter works with TestNG 5.14.2 (and 3 surefire 2.6) (groups
doesn't work in TestNG 5.14)
Here 2 is the pom.xml
I'm using:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>Q4159948</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Q4159948</name>
<url>http://maven.apache.org</url>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.14.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
<configuration/>
</plugin>
</plugins>
</build>
</project>
With a simple AppTest
as follow:
import org.testng.annotations.*;
public class AppTest {
@BeforeClass
public void setUp() {
// code that will be invoked when this test is instantiated
}
@Test(groups = { "fast" })
public void aFastTest() {
System.out.println("Fast test");
}
@Test(groups = { "slow" })
public void aSlowTest() {
System.out.println("Slow test");
}
}
Both 1
$ mvn test -Dtest=AppTest
and
$ mvn test -Dgroups=slow
produce the expected result.
As I've explained in question, any mention 5 of groups either in pom.xml or on command 4 line resulted in reduction of executed tests 3 count. Only way I've managed to avoid this 2 is by using mavens profiles like this:
<profiles>
<profile>
<id>test-slow</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<groups>slow</groups>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
and 1 then running tests with
mvn -P test-slow test
I would suggest to try something like
mvn test -Dincludes=rs/magrathea/TestClassName
although 1 I haven't tested this myself.
In order to run a single test you need the 11 following from official documentation
mvn -Dtest=MyFirstTest test
or 10
mvn -Dtest=MyFirstTest,MySecondTest test
This 9 is tested (and working) on maven 3.
Then 8 you can avoid using the profiles. I had 7 the same problem as I needed to run load 6 test in isolation and using profiler in 5 parallel to get the real figures.
Note: Not 4 sure why but make sure that the switches 3 come before the phase i.e. "-Dtest=MyFirstTest" before 2 "test" otherwise it is not working 1 (Mac OSX)
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.