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

前端 未结 1 1311
猫巷女王i
猫巷女王i 2021-02-09 09:57

I am working on a project with Maven and Surefire plugin v. 2.11. To run single tests I am using -Dtest=TestClass#testMethod and -DforkMode=never (wit

1条回答
  •  深忆病人
    2021-02-09 10:23

    The property maven.surefire.debug is setting the debugForkedProcess parameter of the surefire plugin.

    The documentation for this parameter reads as follows:

    Attach a debugger to the forked JVM. If set to "true", the process will suspend and wait for a debugger to attach on port 5005. If set to some other string, that string will be appended to the argLine, allowing you to configure arbitrary debuggability options (without overwriting the other options specified through the argLine parameter).

    So it will only debug forked JVMs, which explains why it doesn't work when the tests aren't being forked. It isn't able to setup the debugging of a non-forked JVM process that is already running.

    Use mvnDebug

    What you can do instead is use mvnDebug, which allows you to debug the maven process itself - and as your tests are not being forked those as well.

    i.e. instead of mvn -Dtest=TestClass#testMethod test -DforkMode=never you would execute mvnDebug -Dtest=TestClass#testMethod test -DforkMode=never. By default it will listen on port 8000 when it starts maven.

    0 讨论(0)
提交回复
热议问题