简体   繁体   English

使用TestNG和Maven调试Java应用程序

[英]debug java application with TestNG and maven

I'm creating an applicattion that's work with TDD(Test-driven-development). 我正在创建与TDD(Test-driven-development)一起工作的应用程序。 So I create the projects test before development and my doubt is if i can debug the coding test when i execute with maven (mvn clean package). 因此,我在开发之前创建了项目测试,我的疑问是,当我使用maven(mvn clean程序包)执行时是否可以调试编码测试。 Cos testing running with maven. 使用Maven运行Cos测试。 my development environment is: 我的开发环境是:

  • Eclipse Juno Eclipse朱诺
  • Maven 3.0.5 Maven的3.0.5
  • Java 1.6 Java 1.6

Ok I found the solution if sb needs, 好吧,如果某人需要,我找到了解决方案,

By default, Maven runs your tests in a separate ("forked") process. 默认情况下,Maven在单独的(“分支”)进程中运行测试。 You can use the maven.surefire.debug property to debug your forked tests remotely, like this: 您可以使用maven.surefire.debug属性来远程调试分支的测试,如下所示:

mvn -Dmaven.surefire.debug test

The tests will automatically pause and await a remote debugger on port 5005. You can then attach to the running tests using Eclipse. 测试将自动暂停并等待端口5005上的远程调试器。然后,您可以使用Eclipse附加到正在运行的测试。 You can setup a "Remote Java Application" launch configuration via the menu command "Run" > "Open Debug Dialog..." 您可以通过菜单命令“运行”>“打开调试对话框...”来设置“远程Java应用程序”启动配置。

If you need to configure a different port, you may pass a more detailed value. 如果需要配置其他端口,则可以传递更详细的值。 For example, the command below will use port 8000 instead of port 5005. 例如,下面的命令将使用端口8000而不是端口5005。

mvn -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xnoagent -Djava.compiler=NONE" test

link to maven page 链接到Maven页面

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

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