在 Ant 中使用 JUnit
我提到过,如果要进行重构,必须有单元测试,这样才能确保不会破坏代码。 Eclipse 很好地支持 JUnit 。但我更愿意用 Ant 来构建和测试代码,在 Ant 中使用 JUnit 测试。如果您加载一个 Ant 构建文件到 Eclipse 中,运行 Junit Ant 任务,应该会看到:
BUILD FAILED: D:/home/kevinj/Java/Security/ tests.xml:94: Could not create task or type of type: junit.
该信息表明 Ant 没有找到任务或任务所依靠的类。 Ant 试图加载 Junit JAR 文件。当在 IDE 外部使用 Ant 时,应该把 junit.jar 放在 %ANT_HOME%/lib 文件夹。使用 Eclipse 时该任务无法工作,因为它使用自身版本的 Ant 。所以 junit.jar 必须放在 Eclipse 的 Ant 文件夹中,即 %ECLIPSE_HOME%/plugins/org.apache.ant_1.6.2/lib (很显然,不同版本的 Eclipse 会有不同版本的 Ant )。
除了以上步骤,还要配置Eclipse,进入Eclipse然后点击 Window->Preferences->ant->Runtime,然后选择'Ant Home Entries (Default).在点击按钮 'Add External JARs'.选择你junit.jar所在的位置,然后确定ok,再点击apply,你再重新运行该build.xml..........看..得左.是否很高兴?哈哈,我也有过的心情
<!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"> <rdf:Description rdf:about="http://docs.codehaus.org/display/GEOSDOC/Ant+-+junit%2C+build+failed%3D+Could+not+create+task+or+type+of+type+junit" dc:identifier="http://docs.codehaus.org/display/GEOSDOC/Ant+-+junit%2C+build+failed%3D+Could+not+create+task+or+type+of+type+junit" dc:title="Ant - junit, build failed= Could not create task or type of type junit" trackback:ping="http://docs.codehaus.org/rpc/trackback/37859" /> </rdf:RDF> --><!-- Root decorator: all decisions about how a page is to be decorated via the inline decoration begins here. --><!-- Switch based upon the context. However, for now, just delegate to a decorator identified directly by the context. -->
Ant中JUnit测试配置
本文介绍如何在Ant构建工具中正确配置JUnit进行单元测试。详细解释了junit.jar的放置位置,以及如何解决构建失败的问题。

561

被折叠的 条评论
为什么被折叠?



