[英]Calling assertArrayEquals in junit test executed using ant
Im using ant to build my project, and im using junit for writing tests. 我使用蚂蚁来构建我的项目,而我使用junit来编写测试。 I am facing a strange problem.
我面临一个奇怪的问题。 Consider the code below
考虑下面的代码
import junit.framework.*;
public class Test extends TestCase {
public Test(String name) {
super(name);
}
public testA() {
//..Code
Assert.arrayEquals(expected,actual) //This does not work
org.junit.Assert.arrayEquals(expected,actual) //This works !
}
}
Why do i need to append org.junit and not be able to use Assert class directly? 为什么我需要附加org.junit而不能直接使用Assert类? .
。 I have setup junit in my build.xml as follows:
我在build.xml中设置了junit,如下所示:
<property name="lib" value="./lib" />
<property name="classes" value="./build/classes" />
<property name="test.class.name" value="Test"/>
<path id="test.classpath">
<pathelement location="${classes}" />
<pathelement location="./lib/junit-4.10.jar" />
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</path>
<target name="test" depends="compile">
<junit fork="yes" haltonfailure="yes">
<test name="${test.class.name}" />
<formatter type="plain" usefile="false" />
<classpath refid="test.classpath" />
</junit>
</target>
Change 更改
import junit.framework.*;
to 至
import static org.junit.Assert.*;
I'm not exactly sure what the junit.framework
package is for but the import static trick is the common solution and is documented on Assert's Javadoc page . 我不确定
junit.framework
包的用途,但是import static技巧是常见的解决方案,并记录在Assert的Javadoc页面上 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.