package test;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Collection;
import static org.hamcrest.Matchers.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
/*添加运行器*/
@RunWith(Parameterized.class)
public class AeTest {
private int expected;
private int a;
private int b;
/*通过 Parameterized 运行器实现参数化测试*/
/*Collection 单列集合类的根接口,用于存储一系列符合某种规则的元素*/
/*Object[] 可以同时存放不同类型的变量*/
@Parameters
public static Collection<Object[]> data(){
return Arrays.asList(
new Object[][] {
{3, 1, 2},
{5, 4, 1}
}
);
}
public AeTest(int expected, int a, int b) {
this.expected = expected;
this.a = a;
this.b = b;
}
@Test
public void test() {
assertEquals(expected, new Ae().add(a, b));
}
}
Junit4 参数化
于 2022-04-13 19:57:20 首次发布