Debug the JUnit test code in ant in eclipse

Source: Internet
Author: User

Eclipse originally provides the running and debugging functions of JUnit. However, in large-scale project development, ant is often used to maintain the compilation, packaging, and testing of the entire code. However, Environment configuration is often performed before testing. These configurations are often completed by ant, so the test entry starts from running ant, however, it is difficult to debug a JUnit test code.

 

Solution: In the ant script, enable the remote debugging function for JUnit.

 

Eclipse supports remote debugging and can debug Java programs running in different JVMs. Correlation Method visible: http://www.ibm.com/developerworks/cn/opensource/os-eclipse-javadebug/

 

It is not complicated to use the same method in ant.

Assume that you want to debug a JUnit test:

<JUnit printsummary = "yes" fork = "yes" dir = ".">
<Jvmarg line = "-xdebug-xnoagent-djava. compiler = none-xrunjdwp: Transport = dt_socket, Server = Y, suspend = Y, address = 9002"/>

....

<Batchtest>
<Fileset dir = "tests/src">
<Include name = "**/jaxrpc/testutils. Java"/>
</Fileset>
</Batchtest>
</JUnit>

Pay attention to the red part. At this time, JUnit starts remote debugging. When ant runs now, waiting for VM to connect at Port 9002 will be printed .... In this case, create a remote debugging connection to 9002, and place a breakpoint on the corresponding Java code of this test to debug the code.

 

In the same way, all tasks that support the <jvmarg> label can be debugged in this way.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.