简体   繁体   English

如何从Eclipse中的Maven构建调试测试?

[英]How to debug tests from a Maven build in Eclipse?

如何启动Maven构建并让测试出现在Eclipse的调试透视图中?

A package or install is meant to be an atomic action that really shouldn't be stopped for debugging (unless you're debugging a maven plug-in). 包或安装意味着一个原子操作,实际上不应该停止调试(除非你正在调试maven插件)。 You ought to be able to debug the tests by selecting the Eclipse project and doing a "Debug As -> JUnit Test", though. 您应该能够通过选择Eclipse项目并执行“Debug As - > JUnit Test”来调试测试。

If you run the Maven build with the Ecplise Maven Plugin : 如果您使用Ecplise Maven插件运行Maven构建:

  • Place the debug point in java code 将调试点放在java代码中
  • Right click on your pom.xml or your project in Eclipse and Select "Debug As" and then "Maven Install" or If you want an other Maven goal Select "Maven build..." 右键单击Eclipse中的pom.xml或项目,选择“Debug As”,然后选择“Maven Install”或者如果你想要另一个Maven目标选择“Maven build ...”

How to configure it: 如何配置:

  • Create a new Java project in Eclipse. 在Eclipse中创建一个新的Java项目。 Let's call it "Maven debugger project". 我们称之为“Maven调试器项目”。 It's a dummy project and is not intented to contain any code. 这是一个虚拟项目,并不打算包含任何代码。
  • Create a new debug configuration. 创建新的调试配置。 Let's call it "Maven debug launch". 我们称之为“Maven调试启动”。 In the Connect tab, enter "localhost" in the Host field and "5005" in the Port field, which is the port where the Surefire plugin communicates with a debugger. 在Connect选项卡中,在Host字段中输入“localhost”,在Port字段中输入“5005”,这是Surefire插件与调试器通信的端口。 Choose "Standard (Socket Attach)" in Connection Type. 在连接类型中选择“标准(插座连接)”。 In the Source tab, add the projects you want to debug. 在“源”选项卡中,添加要调试的项目。

How to use it: 如何使用它:

  • You can now set breakpoints in your test code. 您现在可以在测试代码中设置断点。
  • Start your "Maven debug launch" in debug 在调试中启动“Maven调试启动”
  • Start your Maven build with the " -Dmaven.surefire.debug " option 使用“ -Dmaven.surefire.debug ”选项启动Maven构建

I found that interesting solution here , and it was useful to me (which mean I tested it, and it worked), so I wanted to share it. 我在这里发现了一个有趣的解决方案,它对我有用(这意味着我测试了它,并且它有效),所以我想分享它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM