在蚂蚁JUnit测试失败,`&LT;&JUnit的GT;`任务,但与`&LT通行证; EXEC&GT;`? [英] JUnit test fails in Ant with `<junit>` task but passes with `<exec>`?
问题描述
我是我的自动化JUnit测试到我的Ant构建。 JUnit的&GT;不过,从IDE和命令行运行,但失败,Ant的&LT时,我简单的测试,只有通过
任务。当我从命令行运行它(我在技术上使用Ant &LT;&EXEC GT;
任务)的结果是:
清理:compile_tests:
[javac的] 2编译源文件到C:\\ MY_TEMPjunit_exec:
[执行] JUnit版本4.10
[执行]。
[执行]时间:0.004
[执行]
[执行] OK(1试验)
[执行]BUILD SUCCESSFUL
总时间:1秒
但是当我使用&LT;&JUnit的GT;
任务:
构建文件:C:\\ MY_TEMP \\ build.xml文件清洁:compile_tests:
[javac的] 2编译源文件到C:\\ MY_TEMPjunit_ant:
[回应] junit_ant开始
[JUnit的]测试SimpleTest的失败BUILD SUCCESSFUL
总时间:0秒
MY_TEMP
是的JUnit 4.10.jar
, SimpleTest.java <的内容/ code>和
的build.xml
。
我抄的JUnit 4.10.jar
到%ANT_HOME%\\ lib目录
文件夹建议由< A HREF =http://ant.apache.org/manual/Tasks/junit.html相对=nofollow>蚂蚁junit任务文档。它已经有了两个蚂蚁的junit.jar
和蚂蚁junit4.jar
。
我的Java版本为1.6.0_26。
我的测试方法是:
//没错,这就是默认包
导入org.junit *。公共类SimpleTest的{ @测试
公共无效mySimpleTest(){
Assert.assertEquals(2,1 + 1);
}}
和我的Ant文件(build.xml文件)是:
&LT;?XML版本=1.0&GT?;
&LT;,项目名称=regression_testsBASEDIR =&GT; &lt;目标名称=干净&GT;
&LT;删除&GT;
&LT;文件集DIR =。包括=*级/&GT;
&LT; /删除&GT;
&LT; /目标与GT; &lt;目标名称=compile_tests取决于=干净&GT;
&LT; javac的SRCDIR =。 DESTDIR =。来源=1.6目标=1.6includeantruntime =false的&GT;
&LT;&类路径GT;
&LT; pathelement位置=./的JUnit 4.10.jar/&GT;
&LT; /类路径&GT;
&LT; / javac的&GT;
&LT; /目标与GT; &lt;目标名称=junit_ant取决于=compile_tests&GT;
&LT;回声消息=junit_ant开始/&GT; &LT;&JUnit的GT;
&lt;试验NAME =SimpleTest的/&GT;
&LT; / JUnit的&GT;
&LT; /目标与GT; &lt;目标名称=junit_exec取决于=compile_tests&GT;
&LT; EXEC可执行=java的DIR =。 &GT;
&LT; ARG值= - 类路径/&GT;
&LT; ARG值=;基于JUnit 4.10.jar/&GT;
&LT; ARG值=org.junit.runner.JUnitCore/&GT;
&LT; ARG值=SimpleTest的/&GT;
&LT; / EXEC&GT;
&LT; /目标与GT;&LT; /项目&GT;
如果一个测试通过的一种方式,而失败的另一个,很可能一些类路径相关,如无法找到受测试的测试类,类,或库。
测试输出应该有助于澄清,如果这是问题所在。
I am automating my JUnit tests into my Ant build. However, my simple test only passes when run from the IDE and commandline but fails with Ant's <junit>
task. When I run it from the commandline (I am technically using the Ant <exec>
task) the result is:
clean:
compile_tests:
[javac] Compiling 2 source files to C:\MY_TEMP
junit_exec:
[exec] JUnit version 4.10
[exec] .
[exec] Time: 0.004
[exec]
[exec] OK (1 test)
[exec]
BUILD SUCCESSFUL
Total time: 1 second
but when I use the <junit>
task:
Buildfile: C:\MY_TEMP\build.xml
clean:
compile_tests:
[javac] Compiling 2 source files to C:\MY_TEMP
junit_ant:
[echo] junit_ant started
[junit] Test SimpleTest FAILED
BUILD SUCCESSFUL
Total time: 0 seconds
The contents of MY_TEMP
are junit-4.10.jar
, SimpleTest.java
, and build.xml
.
I have copied junit-4.10.jar
to the %ANT_HOME%\lib
folder as suggest by the Ant junit task documentation. It already had both ant-junit.jar
and ant-junit4.jar
.
My version of Java is 1.6.0_26.
My test is:
// YES, this is the default package
import org.junit.*;
public class SimpleTest {
@Test
public void mySimpleTest(){
Assert.assertEquals( 2, 1 + 1 );
}
}
And my Ant file (build.xml ), is:
<?xml version="1.0"?>
<project name="regression_tests" basedir=".">
<target name="clean">
<delete>
<fileset dir="." includes="*.class" />
</delete>
</target>
<target name="compile_tests" depends="clean">
<javac srcdir="." destdir="." source="1.6" target="1.6" includeantruntime="false" >
<classpath>
<pathelement location="./junit-4.10.jar" />
</classpath>
</javac>
</target>
<target name="junit_ant" depends="compile_tests" >
<echo message="junit_ant started" />
<junit>
<test name="SimpleTest" />
</junit>
</target>
<target name="junit_exec" depends="compile_tests">
<exec executable="java" dir="." >
<arg value="-classpath" />
<arg value=".;junit-4.10.jar" />
<arg value="org.junit.runner.JUnitCore" />
<arg value="SimpleTest" />
</exec>
</target>
</project>
If a test passes one way, and fails another, it's likely something classpath-related, like it can't find a test class, a class under test, or a library.
The test output should help clarify if this is what the issue is.
这篇关于在蚂蚁JUnit测试失败,`&LT;&JUnit的GT;`任务,但与`&LT通行证; EXEC&GT;`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!