Surefire plugin in Maven

The Surefire Plugin executes the tests (JUnit/testNG) in maven project. Surefire stores the test execution report at /target/surefire-reports. Configuration of surefire plugin
  • suiteXmlFile – specify the xml file containing tests to be executed
  • groups – specify the group names to be included. Tests belonging to those groups will be executed.
  • excludedgroups – specify the group names to be excluded. Tests belonging to those groups will not be executed.
  • parallel – If you want to execute tests in parallel, use this tag. Possible values for this tag can be methods, classes
  • threadCount – How many threads should be created at a time to execute tests?
Here is the sample configuration of surefire plugin
 
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<groups>sanity, regression</groups>
<excludedgroups>smoke</excludedgroups>
<parallel>methods</parallel>
<threadCount>3</threadCount>
</configuration>
</plugin>

Executing the tests through command line

By default, the Surefire Plugin will execute tests from all the classes with their names containing string – Test If you want to execute all tests from the maven project, use below command.

mvn surefire:test

If you want to run tests from single class, you can use below command.

mvn -Dtest=TestCircle test

If you want to run failed tests again, you can execute below command. Meaning of 3 in below command is that test will be executed at the most 3 times.

mvn -Dsurefire.rerunFailingTestsCount=3 test

Web development and Automation testing

solutions delivered!!