views:

2099

answers:

4

I know you can run all the tests in a certain class using:

mvn test -Dtest=classname

But I want to run an individual method and -Dtest=classname.methodname doesn't seem to work.

Thanks -Bill

A: 

To my knowledge, the surefire plugin doesn't provide any way to do this. But feel free to open an issue :)

Pascal Thivent
A: 

You can run a single test class, but not a single method within a test class. You use the simple name of the class not the fully-qualified name of the class. So, if you have a test in "org.sonatype.test.MyTest" and that is the only test you want to run, your command line would look like this:

mvn test -Dtest=MyTest

tobrien
+2  A: 

What I do with my TestNG, (sorry, JUnit doesn't support this) test cases is I can assign a group to the test I want to run

@Test(groups="broken")

And then simply run 'mvn -Dgroups=broken'.

tunaranch
This is a good answer. In my case, the test tried to run but some Seam components weren't set up properly so it looks like this is skipping some portion of the setup code as well.
Chris Williams
Correct. You need to either put groups=broken in in your @BeforeMethod, or do @BeforeMethod(alwaysRun=true)
tunaranch
+1  A: 

New versions of JUnit contains the Categories runner: http://kentbeck.github.com/junit/doc/ReleaseNotes4.8.html

But releasing procedure of JUnit is not maven based, so maven users have to put it manually to their repositories.

Andriy Plokhotnyuk
Nice. But I don't see how this answers the question.
Pascal Thivent