Trying to run ANT JUnit target in debug mode in Eclipse

Here is my goal ANT JUnit

<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 go fine if they run through Eclipse, but they are not deleted if I remove them from ANT. I want it to stop at my break point in Unit test. From the documentation, I know that I need to add these jvmarg, but I can not make it stop, so I obviously do not have them in the right place. Also, I don’t think I have the correct port, but which port should I use? I did not need to configure the debug port when debugging JUnits via eclipse, it just worked

+8
java junit ant
source share
2 answers

You need to forget that you can run JUnit tests and ANT targets from Eclipse. You want to debug a Java application that has the main class org.apache.tools.ant.Main and which can be started using ant from the command line.

Now you have two options: you can create a startup configuration that calls org.apache.tools.ant.Main , but which is quite complicated to configure (you will have to replicate everything that the ant script does at startup).

Another alternative is to properly configure ant . In your case, tests are performed as part of the ant process, but I don’t know an easy way to pass -Xdebug to ANT. Therefore, you must run the tests in a new process. Add this to your junit task:

 <junit fork="yes" forkmode="once" ...> 

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 immediately before the "Conclusion" is important.

+10
source share

Detailed instructions:

  • In Eclipse, go to Run | Debug.
  • Select the remote Java application in the left column. Click Create at the bottom of the same column.
  • On the Create Configuration screen, you will be asked to enter some values. Start with a meaningful name. For the project, select the Java project containing the source code that you want to debug. Leave the default connection type, i.e. Standard (Socket Attach). For the host, enter localhost. If you want to debug the remote server, enter its host name or IP address. For port, enter 5432.
  • Click "Apply."
  • Make sure your tests are running in debug mode. On the same screen, click "Debug". Eclipse will automatically send you to the Debug perspective and you will see a stack trace in the Debug view.
  • If you have not automatically switched to a debugging perspective, select Window | Open Perspective | Other, and then click Debugging.

Taken from here .

+4
source share

All Articles