Maven2 Surefire test plugin


When you run the command "mvn test", this plugin is used

There are special command line parameters you can use:

Skipping tests

Of course you should be running a full suite of tests each time, but on occassions where you want to skip it, add the "-DskipTests" system property to the command line

Running a single test

Use the "test" system property. e.g. add "-Dtest=MySingleTest". This is helpful when you want to test a single test instead of all tests.

Running a test in debug mode

Use the "maven.surefire.debug" system property to tell mvn to wait for a debugger to remotely attach to your test jvm.

e.g. To debug a single test, your command might look something like:

 mvn -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5008" -Dtest=HardToDiagnoseTest test

Maven will pause until you connect your debugger to the maven jvm. I've used this when tests are failing in maven but pass in the IDE.

Published: Monday, 14 February 2011