gpt4 book ai didi

java - 使用 -Dmaven.surefire.debug 和 -DforkMode=never 运行 Maven 测试

转载 作者:搜寻专家 更新时间:2023-10-31 19:45:09 24 4
gpt4 key购买 nike

我正在使用 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 参数。

documentation此参数内容如下:

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).

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

使用mvnDebug

您可以改为使用 mvnDebug ,它允许您调试 maven 进程本身 - 因为您的测试也没有被 fork 。

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

关于java - 使用 -Dmaven.surefire.debug 和 -DforkMode=never 运行 Maven 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31451553/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com