How to run testng-failed.xml using Maven Surefire Plugin

1,555 views
Skip to first unread message

Suresh

unread,
May 6, 2009, 2:31:01 PM5/6/09
to testng-users
I am using maven to run my tests using surefire plugin. But I can't
get the rerun of failed test cases by using different execution.
Below is the plugin section of my pom

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
<properties>
<property>
<name>listener</name>
<value>org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter</
value>
</property>
</properties>
</configuration>
</execution>
<execution>
<id>failed-rerun</id>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${basedir}/target/surefire-reports/testng-
failed.xml</suiteXmlFile>
</suiteXmlFiles>
<properties>
<property>
<name>listener</name>
<value>org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter</
value>
</property>
</properties>
<surefireReportDirectory>${basedir}/output</
surefireReportDirectory>
</configuration>
</execution>
</executions>
</plugin>


and the error I get is as follows


[INFO] [surefire:test]
[INFO] Surefire report directory: /home/company/hudson/workspace/adhoc-
Job/target/surefire-reports

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
Tests run: 1411, Failures: 2, Errors: 0, Skipped: 1409, Time elapsed:
1.486 sec <<< FAILURE!

Results :

Failed tests:
initFramework
(com.company.test.Selenium.product.tests.CalendarMiniCalNavTest)
cleanCaladarInGrid
(com.company.test.Selenium.product.tests.CalendarDefaultTest)

Tests run: 1411, Failures: 2, Errors: 0, Skipped: 1409

[ERROR] There are test failures.

Please refer to /home/company/hudson/workspace/adhoc-Job/target/
surefire-reports for the individual test results.
[INFO] Preparing exec:java
[WARNING] Removing: java from forked lifecycle, to prevent recursive
invocation.
[WARNING] Removing: java from forked lifecycle, to prevent recursive
invocation.
[INFO] No goals needed for project - skipping


If I run the same thing after removing the second execution from the
pom.xml , it works fine.

Mohan KR

unread,
May 6, 2009, 2:44:45 PM5/6/09
to testng...@googlegroups.com
I'm not quite sure what you are trying to do here? So you run the tests and
then you run the failed tests in
the same execution???

Anyways, the suiteXml file *must* exist prior to invocation (in the case
here, you are binding both executions
to the same default phase, which is another problem in itself, look at the
plugin doc. in Maven site). What you
really want to do is move the second execution in a Profile and then
activate the Profile to run failed test, but
make *sure* you don't clean the target directory.

Thanks,
mohan kr

Suresh Daniel

unread,
May 6, 2009, 3:27:02 PM5/6/09
to testng...@googlegroups.com
See my answers below

On Wed, May 6, 2009 at 11:44 AM, Mohan KR <kmoh...@gmail.com> wrote:

I'm not quite sure what you are trying to do here? So you run the tests and
then you run the failed tests in
the same execution???

Yes.
 

Anyways, the suiteXml file *must* exist prior to invocation (in the case
here, you are binding both executions
to the same default phase, which is another problem in itself, look at the
plugin doc. in Maven site). What you
really want to do is move the second execution in a Profile and then
activate the Profile to run failed test, but
make *sure* you don't clean the target directory.

AFAIK, since both are in the same phase (test) and same goal, then the order of execution is based on the order in which it is declared in the pom. So at the end of the first execution (suiteXMLFile - testng.xml) the other file (testng-failed.xml) should be created and available..

As you have suggested, if I move the second execution to another profile, but in the same phase, then what is the syntax for executing both the profile in the same command. I am running this test using hudson. So currently I run "mvn test -P hudson'. Assuiming I create another profile called "hudon-failed-test-rerun", can I execute both the profile together or should I run two separate mvn commands?

Thanks for your suggestion. The above may work for me even if I have to execute in two separate commands.

Suresh


Mohan KR

unread,
May 6, 2009, 4:08:11 PM5/6/09
to testng...@googlegroups.com

I don't know which version of M2 you are using…the ordering is *not* guaranteed in version < 2.0.9.

Second thing, maybe I am missing something here..if the tests from the same suite have failed won't

immediately running those same tests fail again?

 

Use a profile and bind it to different phases (the min. should be test of course) if want to run the mvn

command once (like I said, the $target directory with the testing failed *must* exist for the second

execution) (although I'm still failing to see the point here). Ideally, you run the tests..some fail..you

fix the tests..but don't want to rerun the whole tests..invoke with suiteXml == testing-failed.xml

 

 

Thanks,

mohan kr

Reply all
Reply to author
Forward
0 new messages