使用 -Dmaven.surefire.debug 和 -DforkMode=never 运行 Maven 测试 [英] Run Maven tests with -Dmaven.surefire.debug and -DforkMode=never

查看:47
本文介绍了使用 -Dmaven.surefire.debug 和 -DforkMode=never 运行 Maven 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Maven 和 Surefire 插件 v. 2.11 开发一个项目.要运行单个测试,我使用 -Dtest=TestClass#testMethod-DforkMode=never (没有 DforkMode=never 我无法运行测试因为对象堆空间不足).我习惯了它,它对我很好.所以我正在运行:

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

并且测试运行良好.

但是当我跑步时

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

它只是跳过调试等待"部分并且正在执行测试(我无法使用 IDE 进行连接).mvn -Dmaven.surefire.debug test 对我来说很好用在其他项目中(我不需要关心 fork 模式).

任何想法为什么 forkMode=never-Dmaven.surefire.debug 的组合不能按预期工作?

解决方案

maven.surefire.debug 属性正在设置surefire 插件的debugForkedProcess 参数.>

该参数的文档读取如下:

<块引用>

将调试器附加到 分叉 JVM.如果设置为true",进程将挂起并等待调试器连接到端口 5005.如果设置为其他字符串,该字符串将附加到 argLine,允许您配置任意调试选项(不覆盖另一个通过 argLine 参数指定的选项).

所以它只会调试分叉的 JVM,这就解释了为什么当测试没有分叉时它不起作用.它无法设置已运行的非分叉 JVM 进程的调试.

使用mvnDebug

你可以做的是使用 mvnDebug,它允许您调试 maven 进程本身 - 因为您的测试也不会被分叉.

即您将执行 mvnDebug -Dtest=TestClass#testMethod test -DforkMode=never 而不是 mvn -Dtest=TestClass#testMethod test -DforkMode=never.默认情况下,它会在启动 maven 时监听 8000 端口.

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 (without DforkMode=never I can't run tests because of lack of space for object heap). I got used to it and it was working for me fine. So I am running:

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

and test is run fine.

But when I am running

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

it just skips debug "waiting" part and the test is being executed (I am unable to connect using IDE). mvn -Dmaven.surefire.debug test works for me fine with other project (where I don't need to care about fork mode).

Any ideas why the combination of forkMode=never and -Dmaven.surefire.debug doesn't work as expected?

解决方案

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.

这篇关于使用 -Dmaven.surefire.debug 和 -DforkMode=never 运行 Maven 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆