尝试在Eclipse中运行JUnit的ANT目标在调试模式 [英] Trying to run ANT JUnit target in debug mode in Eclipse

查看:172
本文介绍了尝试在Eclipse中运行JUnit的ANT目标在调试模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的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 laund他们的失败。
我希望它停在单元测试我的破发点。
从技术文档我知道我需要添加这些jvmarg,但不能让它停止,所以我显然不具备他们在正确的地方。
另外,我不认为我有口正确的,但我应该使用什么端口?我没有通过月食调试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 键,可与启动蚂蚁在命令行。

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 但这是pretty复杂设置(你将不得不复制的蚂蚁脚本执行在启动时的一切)。

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).

另一种方法是配置蚂蚁正确。你的情况,测试的蚂蚁进程中运行,但我知道有没有简单的方法来传递 -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 参数将被忽略。

下一步是在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中运行JUnit的ANT目标在调试模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆