Maven Commands for Test Runs

The Commands You Use Daily

CommandWhat it runs
mvn clean testeverything surefire finds (or the suite in pom.xml)
mvn test -Dtest=LoginTestone class
mvn test -Dtest=LoginTest#validLoginone method
mvn test -Dgroups=smokeTestNG group
mvn test -Dsurefire.suiteXmlFiles=testng-smoke.xmla specific suite file
mvn test -Denv=staging -Dbrowser=firefox -Dheadless=truewith 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.