@Parameters:用于JUnit的参数化功能,用来标记准备数据的方法。
注意:该方法需要满足一定的要求:
(1)该方法必须为public static的
(2)该方法返回值必须为java.util.Collection类型
(3)该方法的名字不做要求
(4)该方法没有参数
@RunWith(Parameterized.class )
public class TestDemoParamter {
private String target;
private String except;
@Parameters
public static Collection setParam() {
return Arrays.asList(new Object[][] { { "emplee_info", "empleeInfo" }, // 测试正常情况
{ null, null }, // 测试null时处理情况
{ "", "" }, // 测试空字符串的情况
{ "employee_info", "EmployeeInfo" }, // 测试当首字母大写时的情况
{ "employee_info_a", "employeeInfoA" }, // 测试当尾字母为大写时的情况
{ "employee_a_info", "employeeAInfo" } // 测试多个相连字母大写时的情况
});
}
/**
* 参数化测试必须的构造函数
*
* @param expected 期望的测试结果 ,对应参数集中的第一个参数
* @param target 测试数据,对应结果集中的第二个参数
*/
public TestDemoParamter(String target, String except) {
this.except = except;
this.target = target;
}
@Test
public void testParam(){
Assert.assertEquals(except, target);
}
}