Junit 4 学习笔记(四、Junit Parameters)

@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);
    }
}

转载于:https://my.oschina.net/u/225084/blog/213292

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值