在单元测试中使用assertArrayEquals [英] Using assertArrayEquals in unit tests
本文介绍了在单元测试中使用assertArrayEquals的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的目的是使用 assertArrayEquals(int [],int [])
JUnit方法描述在 API 验证我课程中的一种方法。
My intention is to use assertArrayEquals(int[], int[])
JUnit method described in the API for verification of one method in my class.
但是Eclipse显示了无法识别这种方法的错误消息。这两个进口到位:
But Eclipse shows me the error message that it can't recognize such a method. Those two imports are in place:
import java.util.Arrays;
import junit.framework.TestCase;
我错过了什么吗?
推荐答案
这应该适用于JUnit 4:
This should work with 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});
}
}
(答案基于本wiki文章)
这对于旧的JUnit框架(JUnit 3)是一样的:
And this is the same for the old JUnit framework (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的一个子类(它实现静态assert方法)。
Note the difference: no Annotations and the test class is a subclass of TestCase (which implements the static assert methods).
这篇关于在单元测试中使用assertArrayEquals的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文