2012-01-19 43 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應該工作。 –

相關問題