2012-01-19 42 views
0

使用ant构建我的项目,并使用junit编写测试。我面临一个奇怪的问题。考虑下面在使用ant执行的junit测试中调用assertArrayEquals

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 ! 

    } 
} 

为什么需要追加org.junit并不能直接使用断言类的代码?。我已经安装的JUnit在我的build.xml如下:

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

回答

0

变化

import junit.framework.*; 

import static org.junit.Assert.*; 

我不能完全肯定junit.framework包是什么,但进口静态技巧是常见的解决方案,并记录在Assert's Javadoc page

+0

感谢您的回复。但是这仍然不起作用。如果我调用Assert.assertArrayEquals,我仍然得到符号未找到错误。 – Jim

+0

嗯,奇数,与上面的代码,你甚至不需要Assert类的前缀,即简单地assertArrayEquals应该工作。 –

相关问题