51Testing软件测试论坛
标题:
发一些JUnit4中hamcrest断言的方法
[打印本页]
作者:
liwx2000
时间:
2009-11-23 22:36
标题:
发一些JUnit4中hamcrest断言的方法
assertThat( n, allOf( greaterThan(1), lessThan(10) ) ); //是否既大于1又小于10
assertThat( n, anyOf( greaterThan(1), lessThan(10) ) ); //是否大于1或者小于10
assertThat( n, anything() ); //n是任意值都测试通过
assertThat( str, is( "test" ) ); //str是否为test
assertThat( str, not( "test" ) ); //str是否不为test
assertThat( str, containsString( "test" ) ); //str是否包含test
assertThat( str, endsWith("test" ) ); //str是否以test结尾
assertThat( str, startsWith( "test" ) ); //str是否以test开头
assertThat( n, equalTo( nExpected ) ); //n是否与另外一个n相等
assertThat( str, equalToIgnoringCase( "test" ) ); //str是否与test相等(忽略大小写)
assertThat( str, equalToIgnoringWhiteSpace( "test" ) ); //str是否与test相等(忽略空格)
assertThat( d, closeTo( 3.0, 0.3 ) ); //d是否接近3.0,误差不超过0.3
assertThat( d, greaterThan(3.0) ); //是否大于3.0
assertThat( d, lessThan (10.0) ); //是否小于10.0
assertThat( d, greaterThanOrEqualTo (5.0) ); //是否大于等于5.0
assertThat( d, lessThanOrEqualTo (16.0) ); //是否小于等于16.0
assertThat( map, hasEntry( "test", "test" ) ); //map中是否有test(key)对应的test(value)
assertThat( iterable, hasItem ( "test" ) ); //list中是否包含test对象
assertThat( map, hasKey ( "test" ) ); //map中是否包含test(key)
assertThat( map, hasValue ( "test" ) ); //map中是否包含test(value)
作者:
小不点蜗牛
时间:
2009-12-27 13:47
不错啊
作者:
kaidong12
时间:
2010-3-21 18:53
不错,这个东西好像没有Help doc
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2