问题描述
这是我的 ANT JUnit 目标
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>
如果通过 Eclipse 运行,我的单元测试会通过,但如果我从 ANT 中提取它们,则会失败.我希望它在单元测试中的断点处停止.从文档中我知道我需要添加这些 jvmarg 但无法停止,所以我显然没有将它们放在正确的位置.另外,我认为我的端口不正确,但我应该使用哪个端口?通过eclipse调试JUnits时,我不需要设置任何调试端口,它可以正常工作
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
推荐答案
您需要忘记可以从 Eclipse 内运行 JUnit 测试和 ANT 目标的时刻.您想要的是调试一个 Java 应用程序,该应用程序恰好具有主类 org.apache.tools.ant.Main
并且可以从命令行使用 ant
启动.
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 with ant
from the command line.
您现在有两个选择:您可以创建一个调用 org.apache.tools.ant.Main
的启动配置,但设置起来非常复杂(您必须复制 org.apache.tools.ant.Main
code>ant 脚本在启动时执行).
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 the ant
script does at startup).
另一种选择是正确配置ant
.在您的情况下,测试在 ant
进程中运行,但我不知道将 -Xdebug
传递给 Ant 本身的简单方法.因此,您必须在新进程中运行测试.将此添加到 junit
任务:
The other alternative is to configure ant
correctly. In your case, the tests run within the ant
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 the junit
task:
<junit fork="yes" forkmode="once" ...>
没有这个,jvmarg
参数将被忽略.
Without this, jvmarg
parameters will be ignored.
下一步是在 Eclipse 中创建调试配置.本文详细解释了这一点.对你来说,只有结论"之前的最后一部分很重要.
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.
这篇关于尝试在 Eclipse 中以调试模式运行 ANT JUnit 目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!