Running Maven tests with -Dmaven.surefire.debug and -DforkMode = never

I am working on a project with Maven plugin and Surefire v. 2.11. To run individual tests, I use -Dtest=TestClass#testMethod

and -DforkMode=never

(without DforkMode=never

I cannot run tests due to lack of space for a bunch of objects). I was used to it and it worked well for me. So I run:

mvn -Dtest=TestClass#testMethod test -DforkMode=never

      

and the test runs fine.

But when I run

mvn -Dtest=TestClass#testMethod -Dmaven.surefire.debug test -DforkMode=never

      

it just skips the debug "wait" part and the test is executed (I can't connect with the IDE). mvn -Dmaven.surefire.debug test

works fine for me with another project (where I don't have to care about fork mode).

Any ideas why the combination forkMode=never

and -Dmaven.surefire.debug

does not work as expected?

+3


source to share


1 answer


The property maven.surefire.debug

sets the debugForkedProcess

surefire plugin parameter.

the documentation for this parameter reads like this:

Attach a debugger to the forked JVM . If set to "true", the process pauses and waits for the debugger to attach to port 5005. If it is set to any other line, this line will be added to argLine, allowing you to configure arbitrary debug options (without overwriting other options, specified with the argLine parameter).

This way it will only debug forked JVMs, which explains why it doesn't work when the tests don't fork. It cannot set up debugging of a non-forked JVM process that is already running.



Use mvnDebug

Instead, you can use mvnDebug

that allows you to debug the maven process itself - and since your tests aren't forked too.

i.e. instead mvn -Dtest=TestClass#testMethod test -DforkMode=never

you will execute mvnDebug -Dtest=TestClass#testMethod test -DforkMode=never

. By default it will listen on port 8000 when maven starts.

+4


source







All Articles