简体   繁体   中英

Calling assertArrayEquals in junit test executed using ant

Im using ant to build my project, and im using junit for writing tests. 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? . I have setup junit in my build.xml as follows:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM