Maven surefire plugin suiteXmlFile parallel execution - maven

Is it possible to run parallel execution when there is a suiteXmlFile defined? I have my configuration as below. Also is there anyway we can if the test was executed parallelly in threads? Does it come up in log files?
<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 -->
<parallel>classes</parallel>
<threadCount>10</threadCount>
<suiteXmlFiles>
<suiteXmlFile>mytests.xml</suiteXmlFile>
<!--<suiteXmlFile>suites-test-testng.xml</suiteXmlFile>-->
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>

When you have testng.xml, you can directly mention parallel attribute in testng.xml it self rt, if you have multiple testng files and you want to execute them in parallel, then you may use
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<parallel>classes</parallel>
<threadCount>10</threadCount>
<suiteXmlFiles>
<suiteXmlFile>**/*-testng.xml</suiteXmlFile>
<!--<suiteXmlFile>suites-test-testng.xml</suiteXmlFile>-->
</suiteXmlFiles>
</configuration>
</plugin>

Related

Running just one Test suites with Maven not working

I have in my pom.xml two test suites
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXmlFiles>
<file>src/test/resources/weekly.xml</file>
<file>src/test/resources/monthly.xml</file>
<!-- <suiteXmlFile>${suiteXmlFile}</suiteXmlFile> -->
</suiteXmlFiles>
</configuration>
</plugin>
When I'm trying to run only one from the command line with mnv test -Dsurefire.suiteXmlFile=src/test/resources/monthly.xml
Is running both of them and generate repost for both of them.
How can I run only one xml?
I just checked and executed the pom.xml. If you want to pass the xml file location at the runtime, your pom.xml should look like
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
You can use the maven command mentioned as below to execute :
mvn test -DsuiteXmlFile=src/test/resources/.xml

failsafe+testng run tests that are not explicitly marked with the group name when I request to only run the group

I marked only 1 test class with "http-integration-test" group:
#Test(groups = "http-integration-test", timeOut = 60_000)
public class MyIT
and then ran "mvn clean integration-test". I see multiple tests are run, not just those from this particular class.
why does failsafe maven plugin + testng combination ignore the request to only run "http-integration-test" group?
my pom.xml :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<argLine>-ea -Xmx256m</argLine>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<groups>http-integration-test</groups>
<includes>
<include>**/*IntegrationTest.java</include>
<include>**/*IT.java</include>
<include>**/IT*.java</include>
<include>**/TestServerConfigurator.java</include>
<include>*</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
and here's the parent pom file section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<!-- the default configuration of surefire executes unit
tests implemented using JUnit. please see http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html
for details on these options -->
<configuration>
<!-- -XX:UseSplitVerifier: use legacy class verification; required until javassist can be updated to >= 3.18.2-GA -->
<argLine>-XX:-UseSplitVerifier -XX:MaxPermSize=512m</argLine>
<!-- disable execution of TestNG in case there are both
JUnit and TestNG tests available for execution -->
<testNGArtifactName>none:none</testNGArtifactName>
<excludes>
<!-- Integration Tests end in *IntegrationTest, by
convention -->
<exclude>**/*IntegrationTest.class</exclude>
<exclude>**/*IntegrationTestSuite.class</exclude>
</excludes>
<includes>
<!-- Unit Tests should end in *Test, by convention -->
<include>**/*Test.java</include>
<!-- Include *TestCase, because there are a large
number of tests named this way -->
<include>**/*TestCase.java</include>
</includes>
</configuration>
</plugin>

How to configure testng testsuite in jenkins

I am using Maven project and I have different TestNG suite file. Now I ve to configure Jenkins and POM.xml file where I've to call my individual testsuite from Jenkins. Please help me out how to configure my project.
I've configured my pom.xml file as below
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<includes>
<include>**/*.*</include>
</includes>
<suiteXmlFiles>
<suiteXmlFile>${project.basedir}/src/test/java/com/cisco/citeis/suites/${x‌​mlfile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
In Jenkins I add command clean test -Dsuite= AppFlow.xml
In the POM file add
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<suiteFile></suiteFile>
</properties>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suiteFile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
and in jenkins add the following command
clean test -DsuiteFile=\AppFlow.xml

Multiple test configurations for surefire plugin

I have an issue with my pom:
There are two types of tests running within the project:
Main set of tests using TestNG and JUnit code coverage tests. What I would like is to run JUnit tests on test-compile phase and do not run TestNG tests (which are run on test phase) if previous failed.
As of now I have the following which runs only TestNG:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<argLine>
-javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/1.8.4/aspectjweaver-1.8.4.jar
</argLine>
<properties>
<property>
<name>listener</name>
<value>org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter</value>
</property>
</properties>
<suiteXmlFiles>
<suiteXmlFile>src/test/_all.xml</suiteXmlFile>
</suiteXmlFiles>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
I tried to play with <execution> tag but I can't provide path to TestNG suite then. Any ideas how to combine these tests using surefire plugin and specify different goals?
Solution was to add maven-failsafe-plugin separately from maven-surefire-plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.17</version>
</dependency>
</dependencies>
<configuration>
<includes>
<include>junitcodecoverage/**Test.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<phase>test-compile</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>

How to avoid running surefire unit test with 'mvn site'

whenever I run 'mvn site' all my surefire unit tests gets executed. Is there any way to avoid running surefire unit tests while running mvn site.
My pom is as mentioned below. I am using the below pom in parent project and all the modules are children of this pom.
<plugins>
<!--For Unit tests -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
</plugin>
<!--For executing Integration tests in integration-test phase -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${failsafe.version}</version>
<configuration>
<excludes>
<exclude>**/*Test.java</exclude>
</excludes>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<!--For generating unit and integration test reports -->
<reporting>
<plugins>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.7</version>
<reportSets>
<reportSet>
<reports>
<!--Disable all default reports -->
</reports>
</reportSet>
</reportSets>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>${surefire.version}</version>
<configuration>
<aggregate>true</aggregate>
<linkXRef>true</linkXRef>
</configuration>
</plugin>
</plugins>
</reporting>
As per plugin documentation, use report-only
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>${surefire.version}</version>
<reportSets>
<reportSet>
<reports>
<report>report-only</report>
</reports>
</reportSet>
</reportSets>
</plugin>
surefire-report:report-only: Creates a nicely formatted Surefire Test Report in html format. This goal does not run the tests, it only builds the reports. This is a workaround for https://issues.apache.org/jira/browse/SUREFIRE-257
Try with mvn -DskipTests=true site.

Resources