Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't run single test method with maven

i know how to run Junit test class:

mvn test -Dtest=classname

but when i tried to run a single unit test method as follows:

mvn test -Dtest=classname#methodname

i always get the error: that no test were executed

References:

http://maven.apache.org/plugins/maven-surefire-plugin/examples/single-test.html http://stackoverflow.com/questions/1873995/run-a-single-test-method-with-maven

please advise why my test method is not getting execusted, i am using maven 2 and junit 4.7 .

like image 946
Mahmoud Saleh Avatar asked Nov 21 '11 10:11

Mahmoud Saleh


2 Answers

The syntax above is only supported for Maven Surefire version 2.7.3+

Make sure you're using the correct version of the plugin.

like image 144
Aaron Digulla Avatar answered Sep 30 '22 00:09

Aaron Digulla


There is an issue with surefire 2.12. This is what happen to me changing maven-surefire-plugin from 2.12 to 2.11:

  1. mvn test -Dtest=DesignRulesTest Result: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project pmd: No tests were executed!

  2. mvn test -Dtest=DesignRulesTest Result: [INFO] --- maven-surefire-plugin:2.11:test (default-test) @ pmd --- ... Running net.sourceforge.pmd.lang.java.rule.design.DesignRulesTest Tests run: 5, Failures: 0, Errors: 0, Skipped: 4, Time elapsed: 4.009 sec

like image 24
Duccio Fabbri Avatar answered Sep 30 '22 01:09

Duccio Fabbri