簡體   English   中英

在使用ant執行的junit測試中調用assertArrayEquals

[英]Calling assertArrayEquals in junit test executed using ant

我使用螞蟻來構建我的項目,而我使用junit來編寫測試。 我面臨一個奇怪的問題。 考慮下面的代碼

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而不能直接使用Assert類? 我在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>

更改

import junit.framework.*;

 import static org.junit.Assert.*;

我不確定junit.framework包的用途,但是import static技巧是常見的解決方案,並記錄在Assert的Javadoc頁面上

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM