Maven || Testng || Maven-Surefile
This Article is my scribble pad for maven. Not may details are added
Maven -> build tool in the Java world
plugins -> All task are implemented by plugins.
surefire plugin -> core plugins of the Maven build tool
This plugin has only one goal, test
mvn test -> By default, surefire automatically includes all test classes whose name starts with Test, or ends with Test, Tests or TestCase.
Overview of profile
<profile>
<id>regression</id>
<b>
<!-- Source directory configuration -->
<!--<sourceDirectory>src</sourceDirectory>-->
<plugins>
<!-- Following plugin executes the testng tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<!-- Suite testng xml file to consider for test execution -->
<suiteXmlFiles>
<suiteXmlFile>regression-suite.xml</suiteXmlFile>
</suiteXmlFiles>
<properties>
<property>
<name>testnames</name>
<!--suppress UnresolvedMavenProperty -->
<value>${tests}</value>
</property>
</properties>
<forkMode>never</forkMode>
</configuration>
</plugin>
<!-- Compiler plugin configures the java version to be usedfor compiling
the code -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</b>
</profile>
Using Suite XML Files
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
[...]
</plugins>
Specifying Test Parameters
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<systemPropertyVariables>
<propertyName>firefox</propertyName>
</systemPropertyVariables>
</configuration>
</plugin>
[...]
</plugins>
Using Groups
TestNG allows you to group your tests. You can then execute one or more specific groups. To do this with Surefire, use the groups
parameter, for example:
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<groups>functest,perftest</groups>
</configuration>
</plugin>
[...]
</plugins>
Running Tests in Parallel
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<parallel>methods</parallel>
<threadCount>10</threadCount>
</configuration>
</plugin>
[...]
</plugins>