5

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 .

Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498

3 Answers3

8

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

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

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
3

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

Duccio Fabbri
  • 998
  • 1
  • 10
  • 21
  • Welcome to Stack Overflow! Be careful when posting copy and paste boilerplate/verbatim answers to multiple questions, these tend to be flagged as "spammy" by the community. If you're doing this then it usually means the questions are duplicates so flag them as such instead: http://stackoverflow.com/a/12887047/419 – Kev Oct 14 '12 at 22:47
  • Sorry, you are right, I think there is a duplication: this issue turned out the first time in a comment to the question [link](stackoverflow.com/a/12887047/419) than was formulated as a new question in this page. – Duccio Fabbri Oct 14 '12 at 23:51
1

From Maven project dir execute :

mvn surefire:test -Dtest=<name of test class>

note use of surefire

enter image description here

Reference : https://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html

blue-sky
  • 51,962
  • 152
  • 427
  • 752
  • you're the closest clone to myself on SOF wrt ratio and count of questions to answers and generally the topics involved. In particular : we share a somewhat unusual trait of having a fairly large number of *both* Q&A: we're not afraid to both ask for help and provide it ourselves. Also in the past we both did a lot of Spark – WestCoastProjects Feb 05 '20 at 07:18
  • @javadba thats great!, that is an interesting observation you have made but I think bound to happen given the number of users and topics with activity on this site. – blue-sky Feb 05 '20 at 08:57