如何更轻松地调试 maven surefire 测试(使用 eclipse 作为调试服务器)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3788329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 19:38:27  来源:igfitidea点击:

how to debug maven surefire test more easily (using eclipse as debug server)

eclipsemaven-2debuggingsurefire

提问by mateusz.fiolka

I'm using maven / surefire / eclipse to write some code and later test / debug it.

我正在使用 maven/surefire/eclipse 编写一些代码,然后对其进行测试/调试。

Standard way to do it is by using maven.surefire.debug maven property. By default, when this property is enabled, maven starts listening on port 5005 and I can attach to the debugged process using remote debugger. When the test finishes remote debugger disconnects from the server.

标准方法是使用 maven.surefire.debug maven 属性。默认情况下,启用此属性后,maven 开始侦听端口 5005,我可以使用远程调试器附加到已调试的进程。测试完成后,远程调试器会断开与服务器的连接。

This process involves two steps when done using in eclipse:

在 eclipse 中使用完成时,此过程涉及两个步骤:

  1. Run maven
  2. Connect using remote launch configuration
  1. 运行 Maven
  2. 使用远程启动配置进行连接

What I would like to achieve is to reduce this to:

我想实现的是将其减少到:

  1. Run maven
  1. 运行 Maven

I have found, that setting the maven.surefire.debug property to some remote debug options will change the remote debug behaviour. Thus when I specify i.e.

我发现,将 maven.surefire.debug 属性设置为某些远程调试选项会改变远程调试行为。因此,当我指定即

-Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=5005"

-Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=5005"

then build will try to connect to my eclipse process listening on port 5005. This way I invert the default client/server roles of maven and eclipse.

然后构建将尝试连接到我的 eclipse 进程,监听端口 5005。这样我就反转了 maven 和 eclipse 的默认客户端/服务器角色。

However there is one big problem with this approach. It doesn't give me anything, as after maven build finishes, eclipse stops listening on server port. This is the part that I don't understand. When I connect as debug client from eclipse to for example WebLogic server, it allows me to connect / disconnect freely as many times as I want.

然而,这种方法存在一个大问题。它没有给我任何东西,因为在 maven 构建完成后,eclipse 停止侦听服务器端口。这是我不明白的部分。当我作为调试客户端从 Eclipse 连接到例如 WebLogic 服务器时,它允许我根据需要随意连接/断开连接。

Anyone knows if this is normal, or maybe I need to specify some additional options to make debugging maven tests easier?

任何人都知道这是否正常,或者我可能需要指定一些额外的选项来使调试 Maven 测试更容易?

采纳答案by Zeba Ahmad

Simple way:

简单的方法:

1. Open the Debug As > .. dialogue box
2. In the goal text box, give
     -DforkMode=never test
3. Run the debug project

回答by wmorrison365

Bit late in contributing but thought it was worthwhile still.

贡献有点晚,但认为仍然值得。

In Eclipse debug configuration, create "Maven build" debug config:

在 Eclipse 调试配置中,创建“Maven build”调试配置:

Goals = -Dmaven.surefire.debug test

Profiles = myconfigprofile,weblogic

目标 = -Dmaven.surefire.debug 测试

配置文件 = myconfigprofile,weblogic

or for a specific TestSuite:

或者对于特定的 TestSuite:

Goals = -Dmaven.surefire.debug -Dtest=com.myorg.mypkg/MyTestSuite.java test

Profiles = myconfigprofile,weblogic

目标 = -Dmaven.surefire.debug -Dtest=com.myorg.mypkg/MyTestSuite.java 测试

配置文件 = myconfigprofile,weblogic

N.B. Don't put the props in "JRE/jvm arguments" as this doesn't seem to pause

注意不要将道具放在“JRE/jvm 参数”中,因为这似乎不会暂停

Create additional "Remote Java Application" config:

创建额外的“远程 Java 应用程序”配置:

Host = localhost

Port = 5005

主机 = 本地主机

端口 = 5005

Running/ debugging your mvn build will stop and listen on 5005 by default.

默认情况下,运行/调试您的 mvn 构建将停止并侦听 5005。

启动您的远程调试配置将附加。

See also: http://maven.apache.org/plugins/maven-surefire-plugin/examples/debugging.html

另见:http: //maven.apache.org/plugins/maven-surefire-plugin/examples/debugging.html

回答by Pascal Thivent

If you're using m2eclipse, why not simply right-clickthen Debug > Maven test?

如果您使用的是 m2eclipse,为什么不简单地右键单击然后Debug > Maven test

回答by Rajesh

if you are using Maven 2.0.8+, then it will be very simple,

如果您使用的是 Maven 2.0.8+,那么它会非常简单,

Please refer my answer.

请参考我的回答。

Maven build debug in Eclipse

Eclipse 中的 Maven 构建调试