接口测试从零开始系列4_junit断言介绍2
来源:互联网 发布:开源商城cms 编辑:程序博客网 时间:2024/04/30 11:03
察看junit断言介绍1
需要增加hamcrest
包
在测试类里导入包
importstaticorg.junit.Assert.*;//assertThat跟下面的Matchers配合使用
importstaticcom.taobao.itest.matcher.Matchers.*;//增加了反射相关的匹配,比如验证两个对象的某几个属性相同
//通用匹配符
@Test
publicvoidtestAssert_nomarl()throwsException {
intnum = 200;
String storeId ="123456";
// allOf:所有条件必须都成立
assertThat(num,allOf(greaterThan(100),lessThan(300)));//运行成功
assertThat(num,allOf(greaterThan(100),lessThan(150)));//运行失败
// anyOf:只要有一个条件成立
assertThat(num,allOf(greaterThan(100),lessThan(150)));//运行成功
assertThat(storeId,anyOf(equalTo("123456"),equalTo("1234")));//运行成功
// anything:无论什么条件
assertThat(num,anything()); //运行成功
// is:变量的值等于指定值时
assertThat(storeId,is("123456"));//运行成功
assertThat(num,is("200"));//运行成功
// not:和is相反,变量的值不等于指定值时
assertThat(storeId, notis("123456"));//运行成功
}
//字符串相关匹配符
@Test
publicvoidtestAssert_String()throwsException {
String storeId ="assertTest";
//字符串匹配符
assertThat(storeId,containsString("assert"));//运行成功
// startsWith:字符串变量以指定字符串开头时
assertThat(storeId,startsWith("assert"));//运行成功
// endsWith:字符串变量以指定字符串结尾时
assertThat(storeId,endsWith("t"));//运行成功
// euqalTo:字符串变量等于指定字符串时
assertThat(storeId,equalTo("assertTest"));//运行成功
// equalToIgnoringCase:字符串变量在忽略大小写的情况下等于指定字符串时
assertThat(storeId,equalToIgnoringCase("assertTEst"));//运行成功
// equalToIgnoringWhiteSpace:匹配符断言被测的字符串testedString在忽略头
//尾的任意个空格的情况下等于expectedString,注意:字符串中的空格不能被忽
assertThat(storeId,equalToIgnoringWhiteSpace(" assertTest "));//运行成功
assertThat(storeId,equalToIgnoringWhiteSpace(" assert Test "));//运行失败
}
察看junit断言介绍3
原文:http://www.51testing.com/?uid-128005-action-viewspace-itemid-804269
- 接口测试从零开始系列4_junit断言介绍2
- 接口测试从零开始系列4_junit断言介绍
- 接口测试从零开始系列4_junit断言介绍3
- 接口测试从零开始系列4_junit断言介绍
- 接口测试从零开始系列_mock技术使用
- 接口测试从零开始系列7_Maven使用
- 接口测试从零开始系列_mock技术使用
- 接口测试从零开始系列_mock技术使用
- 接口测试从零开始系列6_简简单单Spring1
- 接口测试从零开始系列6_简简单单Spring2
- http接口测试资料整理系列2--http介绍
- 软件测试_JUnit+Ant构建自动的单元测试(2)
- 接口测试从零开始2------接口测试的全过程2
- 接口测试从零开始系列1_如何针对接口方法设计测试用例
- 黑马程序员_JUnit测试框架
- Android UiAutomator 自动化测试 断言函数介绍
- 接口自动化测试系列之PHPUnit介绍和环境搭建
- 接口测试培训系列2------接口测试的全过程
- 黑马程序员_SQL Server数据的导入小结(1)
- 查询优化
- 开始学习使用Eclipse
- [Accessibility] Missing contentDescription attribute on image
- yii 获取 url action的名字
- 接口测试从零开始系列4_junit断言介绍2
- dhcpcd的静态IP配置方法
- 接口测试从零开始系列4_junit断言介绍3
- 接口测试从零开始5_教你如何使用ibatis
- 设计模式-快餐简解-【代理模式】
- 更新证书错误Code Sign error: Provisioning profile ‘XXXX'can't be found
- 关于checkbox你不得不注意的事情
- splint 编译安装
- web.xml的执行操作