我的意图是使用the API中描述的assertArrayEquals(int[], int[]) JUnit方法来验证类中的一种方法。

但是Eclipse向我显示了无法识别这种方法的错误消息。这两个进口到位:

import java.util.Arrays;
import junit.framework.TestCase;

我错过了什么?

最佳答案

这应该与JUnit 4一起使用:

import static org.junit.Assert.*;
import org.junit.Test;

public class JUnitTest {

    /** Have JUnit run this test() method. */
    @Test
    public void test() throws Exception {

        assertArrayEquals(new int[]{1,2,3},new int[]{1,2,3});

    }
}

(答案基于this wiki article)

这与旧的JUnit框架(JUnit 3)相同:
import junit.framework.TestCase;

public class JUnitTest extends TestCase {
  public void test() {
    assertArrayEquals(new int[]{1,2,3},new int[]{1,2,3});
  }
}

注意区别:没有注释,测试类是TestCase的子类(实现静态断言方法)。

10-07 18:59
查看更多