Always getting "Tests run: 0, Failures: 0, Errors: 0, "even though testng test got executed using "mvn clean test -Dsurefire.suiteXmlFiles=testng.xml" - maven

I am expecting count for Total tests, Passed, Failed should show on console.
I am using latest Testng version 7.4.0. and 2.22.0 surefire version.
I have tried every possible solution but didn't work for me.
Please find my code for maven surefire plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${surefire.suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<includes>
<include>*.*</include>
</includes>
<testFailureIgnore>true</testFailureIgnore>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<reportsDirectory>target/test-report</reportsDirectory>
</configuration>
<dependencies>
</dependencies>
</plugin>
Please let me know if anyone knows any solution.

Related

Test Case pass while running in eclipse with Junit but fails with mvn install

When i run the testcase with Junit it passes but failing with mvn install.
assertEquals(2, flight.getDelayCodes().getLocal().size());
[ERROR] Failures:
[ERROR] FlightEventHandlerTest.testDelayCodesUpdateFields:302 expected:<2> but was:<0>
I tried by adding junit dependecny, still same error
tried with surefire plugin still same error
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>always</forkMode>
<forkCount>4</forkCount>
<argLine>${argLine}</argLine>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<includes>
<include>**/*Test.java</include>
</includes>
<runOrder>failedfirst</runOrder>
</configuration>
</plugin>
After few hours of debugging, building the dependency projects again made trick.Worked for me.

comma separated parametrized maven ONLY tests one testng file

I am facing an issue with Maven which nowhere on internet I could find an answer for it. appreciate if anyone can help me with it. I aiming to test 2 testng files sent as parameter to POM as:
mvn clean test -DsuiteXmlFiles=1.xml,2.xml
and the POM file is:
<plugins>
<!-- Following plugin executes the testng tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<!-- Suite testng xml file to consider for test execution -->
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<!-- Compiler plugin configures the java version to be usedfor compiling
the code -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
but, when i run, it ONLY runs the 2.xml file and runs it twice!!!
tried many options but no matter what is the second xml file it totally ignores the first and runs the second one twice.
can anyone please help?
thanks
Your surefire plugin should look like below
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<suiteXmlFiles>${file}</suiteXmlFiles>
<skipTests>false</skipTests>
</configuration>
</plugin>
Pay close attention to <suiteXmlFiles>${file}</suiteXmlFiles>
So now you can pass in multiple suite files via
mvn clean test -Dfile=src/test/resources/suite-one-with-execution.xml, src/test/resources/suite-two-with-execution.xml
For more details you can refer to my blog post here.
finally understood where the issue was, for some reason i still dont know why, the Suite name in xml files should be not same as each other!!

How to run scala test case using Maven

I have written my project in java and scala.
I have written one scala test case for unit testing scala code.
However, I am not sure about the path it has to be stored to because maven says,
T E S T S
------------------------------------------------------- There are no tests to run.
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
Can anybody help me with how can I have maven pick my scala test file stored under src/test/scala?
]4
Below should be the folder structure to run your test cases. Just like java test case execution from maven scala test will also execute....
please go through scala with Maven doc here
Please refer sample pom.xml here
http://www.scalatest.org/user_guide/using_the_scalatest_maven_plugin
To use the ScalaTest Maven plugin, you need to disable SureFire and enable ScalaTest. Here's an example of how to do this in your pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!-- enable scalatest -- >
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<junitxml>.</junitxml>
<filereports>WDF TestSuite.txt</filereports>
</configuration>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>

TestSuite Execution Order in Maven

My unit tests are incremental. That is, each test tests one particular function but there is dependency on the functioning of previous tests....perhaps not orthodox, but it is robust.
Within a test suite, tests are ordered by the order provided in the #Suite.SuiteClasses annotation.
Maven (surefire plugin), seems to order test suites in alphabetical order:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<includes>
<include>**/ModelTestSuite.java</include>
<include>**/ServiceTestSuite.java</include>
<include>**/ZFlowTestSuite.java</include>
</includes>
<additionalClasspathElements>
<additionalClasspathElement>${webinf.dir}</additionalClasspathElement>
</additionalClasspathElements>
<systemPropertyVariables>
<log4j.configuration>file:${l4j.test}/log4j.test.properties</log4j.configuration>
</systemPropertyVariables>
</configuration>
</plugin>
If I want FlowTestSuite to run after ServiceTestSuite, then I rename it ZFlowTestSuite.
This works but it feels like a hack. Is there an alternative approach?

How to tell Maven to execute testng tests one by one each in new JVM instance?

Is it possible to tell Maven to execute every testng test in new JVM instance (fork) in serial mode, i.e. one by one.
The configuration below works for junit, but not works for testng
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<forkMode>always</forkMode>
</configuration>
Does anybody know how to set for testng?
#ben75, Thanks for your answer, But it doesn't work for me.
The key point is we use suiteXmlFiles to specify which case to run, and if we use suiteXmlFiles, the forkMode or (forkCount resuseForks) don't work.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<includes>
<include>**/Test*.java</include>
</includes>
<forkMode>always</forkMode>
</configuration>
</plugin>
This configuration works for me.
You can use this
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
...
It's a very expensive configuration (i.e. it will take a long time to run your tests... so it's better to not use it, but you probably have some (good ?) reasons to use it).
This solution is the way to go since version 2.14, so I suggest you to upgrade your surefire-plugin version.
the reference is here

Resources