Running just one Test suites with Maven not working - maven

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

Related

How to add multiple plugin in same pom.xml file

I have two project, which run on two different platform Android and Ios. which i am controlling by different suite runner file . when i am trying to run same via Maven , whichever plugin mention last , only that profile run , how can i make working of all.
<plugins>
<!-- build standalone exe jar -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<skip>false</skip>
<mainClass>platform.atcios.SuiteRunner</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<skip>false</skip>
<mainClass>platform.atc.SuiteRunner</mainClass>
</configuration>
</plugin>
</plugins>
</build>
in this , if atc is mention in last , when run for ios , atcios giving build fail error and viceversa.
how to make both work
You need to define different <executions> inside the same <plugin> tag.
Each <execution> may have its own <configuration>.

Maven surefire plugin suiteXmlFile parallel execution

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>

Maven + Surefire: Overwrite temp and output directory

I am trying to overwrite temporary and output directory for surefire plugin. I have following plugin definition:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<tempDir>c:/tmp/a-tests-temp</tempDir>
<outputDirectory>c:/tmp/a-tests-out</outputDirectory>
</configuration>
</plugin>
It does not work. It continue using /target/surefire and target/surefire-reports.
The idea is to split different concurrency maven test runs over the same project directory for quick tests on the developer workstation.
Sorry for late reply, ive only managed to use relative path location to change the path for the temp folder
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<testClassesDirectory>${project.buildDirectory}/test-classes</testClassesDirectory>
<reportsDirectory>${project.buildDirectory}/surefire-reports</reportsDirectory>
<classesDirectory>${project.buildDirectory}/test-classes</classesDirectory>
<tempDir>../${project.buildDirectory}/surefire</tempDir>
<useFile>false</useFile>
<includes>
<include>**/*Spec.*</include>
</includes>
<systemPropertyVariables>
<geb.env>${geb.env}</geb.env>
<geb.build.reportsDir>${project.buildDirectory}/${geb.build.reportsDir}</geb.build.reportsDir>
<com.athaydes.spockframework.report.outputDir>${project.buildDirectory}/spock-reports</com.athaydes.spockframework.report.outputDir>
<com.athaydes.spockframework.report.aggregatedJsonReportDir>${project.buildDirectory}/spock-reports</com.athaydes.spockframework.report.aggregatedJsonReportDir>
</systemPropertyVariables>
<testFailureIgnore>true</testFailureIgnore>
</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

Is testng.xml file updated automatically

When running testng with mvn, I configured my workspace as required:
My pom.xml file is configured with all the required dependencies and testng.xml contains all the required classes.
Yet, when I add a new test class, the testng.xml isn't updated automatically-
Shouldn't it scan from the root for the corresponding tests? Or will I have to update the testng.xml file manually?
(BTW, my workspace is configured according to the following post: How to call testng.xml file from pom.xml in Maven)
The xml method gives you more granular control of your test sets. It will not be altered automatically, although eclipse will generate xml configs on the fly if you select say a folder and right click run as testng. If you would just like to run all testng annotated test and you have maven configured properly with surefire or failsafe, you don't even need an xml file. Just run "mvn verify" and all test should be run based on annotation. If this doesn't work, please post your surefire/failsafe pom sections.
If you want to configure a particular xml in maven, use something like (surefire or failsafe work the same.):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${failsafe.version}</version>
<configuration>
<argLine>-Xmx1024m</argLine>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
<!-- <groups>functest,perftest</groups> -->
</suiteXmlFiles>
</configuration>
</execution>
</executions>
</plugin>
If you do need more granular control, and would like to use an xml file specified by maven, you launch it via "verify -P MyProfile"
<profiles>
<profile>
<id>MyProfile</id>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>MyProfile.xml</suiteXmlFile>
<!-- <groups>functest,perftest</groups> -->
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>MyOtherProfile</id>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>MyOtherProfile.xml</suiteXmlFile>
<!-- <groups>functest,perftest</groups> -->
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profiles>

Resources