Thursday, 24 February 2011

Maven Surefire executing only one test method in a test class

I have just worked on a improvement in Apache Maven Surefire Plugin.
Most of the time you have a test class which contains a lot of test methods.
When only one failed you have to execute all methods of the class (with -Dtest=MyClass)
This can be long and boring :-).

So now (see [1]), you will be able to use -Dtest=MyClass#myMethod to execute only the method called myMethod from the test class MyClass.

The feature has been pushed in a github fork [2].
Why in a github fork : I'd like to have feedback fast :-)

So how to test it ? :

Get the sources :

git clone git://
cd maven-surefire
mvn clean install (add -DskipTests if you don't want to execute all integration tests).

Update you pom :


And now test it :-)

-Dtest=MyTestClass#myMethod (note the support of * : -Dtest=MyTestClass#*Method )

NOTE : supported only for junit 4.x

Update : now supported for testng too.

Update 25 Feb : merged in ASF svn repo

Update 12 March : released in surefire 2.8 (Yeahhh :-) )

Have Fun ! (and don't miss to put feedback in case of issues)



Mani said...

In our FlexUnit test framework, a number of test case classes contain tests. While running them using maven, I need to skip certain tests (methods) by providing the test names in a property file.

I'm looking forward to any information towards dynamically enabling and disabling any test’s run when using maven

Is there some way to do this i.e. to exclude few tests and run all other tests of a class.

Any info would be highly appreciated.

Anonymous said...
This comment has been removed by a blog administrator.