Careeroza
Maven Commands for Test Runs
The Commands You Use Daily
| Command | What it runs |
|---|---|
mvn clean test | everything surefire finds (or the suite in pom.xml) |
mvn test -Dtest=LoginTest | one class |
mvn test -Dtest=LoginTest#validLogin | one method |
mvn test -Dgroups=smoke | TestNG group |
mvn test -Dsurefire.suiteXmlFiles=testng-smoke.xml | a specific suite file |
mvn test -Denv=staging -Dbrowser=firefox -Dheadless=true | with system properties read by ConfigReader |
Surefire Configuration
Example
Let the suite file be chosen from the command line, with a default:
pom.xml
<properties>
<suiteXml>testng.xml</suiteXml>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suiteXml}</suiteXmlFile>
</suiteXmlFiles>
<testFailureIgnore>false</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>Example output
$ mvn clean test -DsuiteXml=testng-smoke.xml [INFO] --- surefire:3.5.1:test (default-test) @ shopease-ui-tests --- [INFO] Running TestSuite [INFO] Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 61.3 s [INFO] BUILD SUCCESS
Note: A failed test makes mvn test exit with code 1 (BUILD FAILURE). CI marks the build red automatically. Keep testFailureIgnore false unless a later step decides pass/fail.