Running Testng.xml from POM.xml is not running tests in sequence - java

I am running testng.xml file using POM.xml by adding compiler and surefire plugins. It runs test but the sequence of tests is not as expected.
I have 10 classes mentioned in testng.xml and it runs in that sequence when i run through testng.xml. But when running through POM.xml the sequence goes like; first it runs all the 0 priority tests mentioned in all classes, then 1 priority tests and so on. It should run tests according to the classes sequence mentioned in testng.xml.
Any quick help will be much appreciated.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>${jdk.level}</source>
<target>${jdk.level}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>

under testng dependency the scope tag needed to be changed to compile from test and it resolved the issue as it needed to compile the build after adding plugins.
It resolved the issue.

Related

Running junit testcases in parallel using maven

I added in my pom.xml the following plugin to run test classes in parallel
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<parallel>classes</parallel>
<threadCount>10</threadCount>
<systemPropertyVariables>
<profile.name>${profile.name}</profile.name>
</systemPropertyVariables>
<forkCount>1</forkCount>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
And i have
#RunWith(Suite.class)
#Suite.SuiteClasses({
test_1.class,
test_2.class
})
when i run it as a junit test it runs sequential not parallel... any help ??
<forkCount>1</forkcount> means 1 thread!
The default setting is forkCount=1/reuseForks=true, which means that maven-surefire-plugin creates one new JVM process to execute all tests in one Maven module.
from: https://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html#Forked_Test_Execution
To run them in parallel, you should choose a forkCount > 1, and (to be safe) also <reuseForks>false</reuseForks>.

maven exclude tests with surefire excludeTests option

I have a large project with sub-projects and want to use excludesFile to exclude test failures, and ignore them until the tests are fixed.
I believe there might be a way of achieving this with surefire plugin excludesFile option here.
I am very new to maven and would like get some examples or pointers on how this can be achieved.
To use excludesFile option,
Create a file containing file name patterns of your test files that you want to exclude.Example:Create a file at src/main/resources/exclude.txt with below 2 lines.
**/*1.java
**/*2.java
Add following in your maven-surefile-plugin configuration.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<excludesFile>src/test/resources/exclude.txt</excludesFile>
</configuration>
</plugin>
</plugins>
You are done. All test files ending with 1.java and 2.java will be excluded.
There is other way also to exclude any tests from execution by using configuration in maven-surefire-plugin.
Example:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<excludes>
<exclude>**/TestCircle.java</exclude>
<exclude>**/TestSquare.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
More information can be found here.

What configuration required to run maven project with selenium (TestNG) from command line?

Required Configuration for running maven project from command line.
Very Nice question.
I had also stuck with same question but I have found solution.
Required two maven plug-ins which are given under.
Please make sure your JDK 1.7 and JRE 7 version is configure in your project.
Add this plugin to your pom.xml and follow this step:
1 mvn clean
2 mvn install
3 mvn exec:java
Step 3 is required to run project without specify main class
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>${project.build.sourceEncoding}</encoding>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<executable>${env.JAVA_HOME}/bin/javac</executable>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>com.mainClass</mainClass>
</configuration>
</plugin>

SOAPUI tests reporting in Maven

I have integrated SOAPUI with Maven so that my test cases can be executed with Maven build.
It works fine.
But this integration does not create any formatted report which i can refer to know the test results, like an HTML output.
For the same I added a plugin in my POM.XML (shown below)
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.6</version>
</plugin>
</plugins>
</reporting>
This creates the report, but it does it for all the junit test cases which are in my project.
I can not see any report on the SOAPUI test case.
How can I make the Surefire report contain the SoapUI test results?
Just got it working in my setup.
The solution is "maven-surefire-report-plugin" converts the "TEST*.xml" in to HTML format which is placed in "/targets/surefire-report".So make sure "soapui-maven-plugin" is placing the output in of the "soapui-maven-plugin" in "/targets/surefire-report" directory.
Please see the sample below
<plugin>
<groupId>com.smartbear.soapui</groupId>
<artifactId>soapui-maven-plugin</artifactId>
<version>5.1.2</version>
<executions>
<execution>
<phase>test</phase>
<goals><goal>test</goal></goals>
<configuration>
<projectFile>${baseDirectory}/src/test/integration/resources/Mobile-Ads-soapui-project.xml</projectFile>
<iface>mobileAdsService</iface>
<outputFolder>${baseDirectory}/target/surefire-reports/</outputFolder>
<junitReport>true</junitReport>
<exportwAll>true</exportwAll>
<printReport>true</printReport>
<testFailIgnore>false</testFailIgnore>
</configuration>
</execution>
</executions>
</plugin>

Is there a way to specify in Maven which JUnit tests run by package

I'm wondering if there is a way to specify in Maven which collection of JUnit tests run based on package names. An 'exclude' would be ideal, since I have fewer that I need not run than I have those that need to run.
Yes you can configure surefire plugin to include certain tests only
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<includes>
<include>com/abc/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html

Categories