如何更轻松地调试maven Surefire测试(使用eclipse作为调试服务器)
我正在使用 maven / Surefire / Eclipse 编写一些代码,然后对其进行测试/调试。
标准方法是使用 maven.surefire.debug maven 属性。默认情况下,启用此属性后,maven 开始侦听端口 5005,我可以使用远程调试器附加到被调试的进程。测试完成后,远程调试器将与服务器断开连接。
在 eclipse 中使用时,此过程涉及两个步骤:
- 运行 maven
- 使用远程启动配置
Connect我想要实现的是将其减少为:
- 运行 maven
我发现,将 maven.surefire.debug 属性设置为一些远程调试选项将改变远程调试行为。因此,当我指定 ie
-Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=5005"
然后构建将尝试连接到在端口 5005 上侦听的 eclipse 进程。这样我就反转了默认的客户端/服务器角色Maven 和 Eclipse 的。
然而,这种方法有一个大问题。它没有给我任何东西,因为在 Maven 构建完成后,Eclipse 停止监听服务器端口。这是我不明白的部分。 当我作为调试客户端从 Eclipse 连接到 WebLogic 服务器时,它允许我根据需要多次自由连接/断开连接。
任何人都知道这是否正常,或者我可能需要指定一些额外的选项以使调试 Maven 测试更容易?
I'm using maven / surefire / eclipse to write some code and later test / debug it.
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.
This process involves two steps when done using in eclipse:
- Run maven
- Connect using remote launch configuration
What I would like to achieve is to reduce this to:
- Run 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.
-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.
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.
Anyone knows if this is normal, or maybe I need to specify some additional options to make debugging maven tests easier?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
简单的方法:
Simple way:
贡献有点晚了,但认为还是值得的。
在 Eclipse 调试配置中,创建“Maven build”调试配置:
或针对特定 TestSuite:
测试不要将属性放入“JRE/jvm 参数”中,因为这似乎不会暂停
创建额外的“远程 Java 应用程序”配置:
运行/调试您的 mvn 构建将默认停止并监听 5005。
Starting your remote debug config will attach.
参见:
http://maven.apache.org/plugins/maven-surefire -plugin/examples/debugging.html
Bit late in contributing but thought it was worthwhile still.
In Eclipse debug configuration, create "Maven build" debug config:
or for a specific TestSuite:
N.B. Don't put the props in "JRE/jvm arguments" as this doesn't seem to pause
Create additional "Remote Java Application" config:
Running/ debugging your mvn build will stop and listen on 5005 by default.
Starting your remote debug config will attach.
See also:
http://maven.apache.org/plugins/maven-surefire-plugin/examples/debugging.html
如果您使用的是 m2eclipse,为什么不简单地右键单击然后调试> Maven 测试?
If you're using m2eclipse, why not simply right-click then Debug > Maven test?
如果你使用的是Maven 2.0.8+,那么它会很简单,
请参考我的答案。
Eclipse 中的 Maven 构建调试
if you are using Maven 2.0.8+, then it will be very simple,
Please refer my answer.
Maven build debug in Eclipse