Here is my ANT JUnit target
<target name="test" depends="compile" >
<junit failureProperty="test.failure" >
<jvmarg value="-Xdebug" />
<jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5432" />
<classpath>
<pathelement path="${basedir}\..\Core\lib\junit-4.10.jar"/>
<pathelement path="${basedir}\..\Suggestion\lib\ssce.jar"/>
<pathelement path="C:\Java\javamail-1.4.1\mail.jar"/>
<pathelement path="C:\Java\commons-net-2.0\commons-net-ftp-2.0.jar"/>
<pathelement path="${basedir}\WebContent\WEB-INF\lib\gson-2.2.1.jar"/>
<pathelement path="${tomcatLibs}\servlet-api.jar"/>
</classpath>
<classpath>
<pathelement path="${build}"/>
</classpath>
<formatter type="brief" usefile="false" />
<test name="com.server.junit.ServerTestSuite" />
<test name="com.junit.DictionaryTestSuite" />
<test name="com.util.junit.SuggestionTestSuite" />
</junit>
<fail message="Unit test failed" if="test.failure"/>
</target>
My unit tests pass fine if run through Eclipse but fail if I laund them from ANT. I want it to stop at my break point in a Unit test. From documentation I know I need to add these jvmarg but can't get it to stop so I obviously don't have them in the right place. Also, I don't think I have the port correct but what port should I use? I didn't have to set up any debug port when debugging JUnits through eclipse, it just worked
You need to forget a moment that you can run JUnit tests and ANT targets from within Eclipse. What you want is to debug a Java application that happens to have the main class
org.apache.tools.ant.Main
and which can be started withant
from the command line.You have now two options: You can create a launch config that invokes
org.apache.tools.ant.Main
but that's pretty complicated to set up (you will have to replicate everything that theant
script does at startup).The other alternative is to configure
ant
correctly. In your case, the tests run within theant
process but I know no simple way to pass-Xdebug
to Ant itself. Therefore, you must run the tests in a new process. Add this to thejunit
task:Without this,
jvmarg
parameters will be ignored.The next step is to create a debug configuration in Eclipse. This article explains this in detail. For you, only the last part right before "Conclusion" is important.
Detailed instructions:
Taken from here.