TestNG Maven Surefire Plugin Configurations

Filed Under: TestNG

TestNG Maven surefire plugin configurations let us define which tests to execute when we run the maven build. When we have a large project with many test cases, then it comes handy to configure only specific test suites for execution.

TestNG Maven Project

During the series of TestNG Tutorials here, I have created a lot of test classes and TestNG XML suite files. Below image shows the current project structure and all the test classes it has.

TestNG Maven Project

Now when I run a maven build, it scans the project and executes all the test classes. So project build takes a lot of time. If I am interested in specific tests only, chances are that its logging gets lost in all the noise created by other tests.

TestNG maven build running all tests

Maven Surefire Plugin

Maven surefire plugin is used to run the project tests. It also allows us to configure which XML suites to execute when we build our project. Below configuration will tell maven surefire plugin to execute only testng.xml and test_parameters.xml test suite files.


<build>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-surefire-plugin</artifactId>
			<version>2.21.0</version>
			<configuration>
                   <!-- TestNG Suite XML files list for test execution -->
                   <suiteXmlFiles>
                       <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
                       <suiteXmlFile>src/test/resources/test_parameters.xml</suiteXmlFile>
                   </suiteXmlFiles>
               </configuration>
		</plugin>
	</plugins>
</build>

Now when we perform maven build by running mvn clean install or mvn test commands, we get a clean output for our tests.

TestNG Maven Surefire plugin XML Suite files

That’s all for configuring maven-surefire-plugin to execute only specific TestNG XML suite files.

You can download the example code from our GitHub Repository.

Comments

  1. chandrika.Chilakalapudi says:

    I am getting following error,pleases help me with thses
    1.WebDriver Timed out waiting for driver server to start
    2.org.openqa.selenium.net.UrlChecker$TimeoutException
    3.java.util.concurrent.TimeoutException

  2. raja says:

    Hi , i am trying to download the project from GitHub, there is no option to download this particular project, so i had downloaded the root folder , which have so many projects, for some unknown reason, i am not able to find the TestNG-Examples project in it. please help me.

Leave a Reply

Your email address will not be published. Required fields are marked *

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages