Debug TestNg java code in eclipse that uses Ant

2019-07-24 01:05发布

问题:

I am trying to debug a project in Eclipse(Mars) that does test automation using TestNg and Apache Ant for build. With the available solutions, I am able to debug ant build.xml file, but breakpoints inside java code are not hitting. Can anyone please help me with this on how to debug java source files, especially the test cases in my case in eclipse?

Thanks.

回答1:

I have similar problem, may be it is TestNG bug. But all breakpoints are halting execution if I'm starting not single test (with right-click menu, for example), but starting all Test Suite with *.xml suite-file.



回答2:

I figured the solution to this problem. Follow the following steps to solve this
1. Add following lines inside the task in build.xml file.

<jvmarg value="-Xdebug" />
<jvmarg value="-Xnoagent"/> 
<jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5432" />
  1. Add remote java application debug configuration, i.e., specify project name, give host as "localhost", and port same as in step 1, 5432 in our case
  2. Debug the build.xml file first
  3. Attach the testng process, by start debugging the remote java application debug configuration set in step 2.