assertThat
JUnit4.4引入了Hamcrest框架,Hamcest提供了一套匹配符Matcher,这些匹配符更接近自然语言,可读性高,更加灵活
/**equalTo匹配符断言被测的testedValue等于expectedValue,
* equalTo可以断言数值之间,字符串之间和对象之间是否相等,相当于Object的equals方法
*/
assertThat(testedValue, equalTo(expectedValue));
/**equalToIgnoringCase匹配符断言被测的字符串testedString
*在忽略大小写的情况下等于expectedString
*/
assertThat(testedString, equalToIgnoringCase(expectedString));
/**equalToIgnoringWhiteSpace匹配符断言被测的字符串testedString
*在忽略头尾的任意个空格的情况下等于expectedString,
*注意:字符串中的空格不能被忽略
*/
assertThat(testedString, equalToIgnoringWhiteSpace(expectedString);
/**containsString匹配符断言被测的字符串testedString包含子字符串subString**/
assertThat(testedString, containsString(subString) );
/**endsWith匹配符断言被测的字符串testedString以子字符串suffix结尾*/
assertThat(testedString, endsWith(suffix));
/**startsWith匹配符断言被测的字符串testedString以子字符串prefix开始*/
assertThat(testedString, startsWith(prefix));
/**nullValue()匹配符断言被测object的值为null*/
assertThat(object,nullValue());
/**notNullValue()匹配符断言被测object的值不为null*/
assertThat(object,notNullValue());
/**is匹配符断言被测的object等于后面给出匹配表达式*/
assertThat(testedString, is(equalTo(expectedValue)));
/**is匹配符简写应用之一,is(equalTo(x))的简写,断言testedValue等于expectedValue*/
assertThat(testedValue, is(expectedValue));
/**is匹配符简写应用之二,is(instanceOf(SomeClass.class))的简写,
*断言testedObject为Cheddar的实例
*/
assertThat(testedObject, is(Cheddar.class));
/**not匹配符和is匹配符正好相反,断言被测的object不等于后面给出的object*/
assertThat(testedString, not(expectedString));
/**allOf匹配符断言符合所有条件,相当于“与”(&&)*/
assertThat(testedNumber, allOf( greaterThan(8), lessThan(16) ) );
/**anyOf匹配符断言符合条件之一,相当于“或”(||)*/
assertThat(testedNumber, anyOf( greaterThan(16), lessThan(8) ) );
/**closeTo匹配符断言被测的浮点型数testedDouble在20.0¡À0.5范围之内*/
assertThat(testedDouble, closeTo( 20.0, 0.5 ));
/**greaterThan匹配符断言被测的数值testedNumber大于16.0*/
assertThat(testedNumber, greaterThan(16.0));
/** lessThan匹配符断言被测的数值testedNumber小于16.0*/
assertThat(testedNumber, lessThan (16.0));
/** greaterThanOrEqualTo匹配符断言被测的数值testedNumber大于等于16.0*/
assertThat(testedNumber, greaterThanOrEqualTo (16.0));
/** lessThanOrEqualTo匹配符断言被测的testedNumber小于等于16.0*/
assertThat(testedNumber, lessThanOrEqualTo (16.0));
/**hasEntry匹配符断言被测的Map对象mapObject含有一个键值为"key"对应元素值为"value"的Entry项*/
assertThat(mapObject, hasEntry("key", "value" ) );
/**hasItem匹配符表明被测的迭代对象iterableObject含有元素element项则测试通过*/
assertThat(iterableObject, hasItem (element));
/** hasKey匹配符断言被测的Map对象mapObject含有键值“key”*/
assertThat(mapObject, hasKey ("key"));
/** hasValue匹配符断言被测的Map对象mapObject含有元素值value*/
assertThat(mapObject, hasValue(value));
分享到:
相关推荐
junit-4.11和hamcrest-core-1.3 的jar包,用于java 单元测试,需要的可以下载
junit.jar + hamcrest-core.jar + hamcrest-library.jar,测试必备包
junit4.9b3+hamcrest-1.3.0RC2的jar包
单元测试jar(junit-4.11+hamcrest-core-1.3.rc2).!!!!!
这是JUnit4.12及hamcrest-core-1.3的jar包,用eclipse进行Junit测试时会用到
junit-4.12.jar hamcrest-library-1.3.rc2.jar hamcrest-core-1.3.rc2.jar,单元测试框架JUnit必须引用的jar包
JUnit是由 Erich Gamma 和 Kent Beck 编写的一个回归测试框架(regression testing framework)。Junit测试是程序员测试,即所谓白盒测试,因为程序员知道被测试的软件如何(How)完成功能和完成什么样(What)的...
assertThat断言语句 Marchers提供各种数值匹配方法、字符串匹配方法使用
包含Junit 4.12 及 hamcrest-core 1.3 所有jar包 ,为JUnit最新工具包。
junit测试所需jar包,包含4.11和4.12两个版本以及hamcrest-core-1.3.jar等jar,是进行junit测试不可缺少的包
junit4.11+hamcrest-all-1.3.jar, junit4.11+hamcrest-all-1.3.jar, junit4.11+hamcrest-all-1.3.jar, junit4.11+hamcrest-all-1.3.jar
详细介绍了junit4测试框架的使用和特性
junit-4.11.jar hamcrest-core-1.3.jar
NULL 博文链接:https://xizhongshui.iteye.com/blog/1604587
开发junit4所用到的3个jar包,可用最新断言assertThat,包括了hamcrest-core-1.3.0RC2.jar, hamcrest-library-1.3.0RC2.jar和 junit-4.8.1.jar三个jar包
JUnit4.11 及 hamcrest1.3 jar包。
junit4.13jar包和hamcrest-all-1.3.jar,以及这两个jar包的源码
进行项目测试时为了进行junit测试生成HTML文档这是必须的包,有时官网会延迟不好下载,这里提供给大家学习参考