/**equalTo匹配符斷言被測的testedValue等于expectedValue,
* equalTo可以斷言數(shù)值之間,字符串之間和對象之間是否相等,相當(dāng)于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結(jié)尾*/
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等于后面給出匹配表達(dá)式*/
assertThat(testedString, is(equalTo(expectedValue)));
/**is匹配符簡寫應(yīng)用之一,is(equalTo(x))的簡寫,斷言testedValue等于expectedValue*/
assertThat(testedValue, is(expectedValue));
/**is匹配符簡寫應(yīng)用之二,is(instanceOf(SomeClass.class))的簡寫,
*斷言testedObject為Cheddar的實(shí)例
*/
assertThat(testedObject, is(Cheddar.class));
/**not匹配符和is匹配符正好相反,斷言被測的object不等于后面給出的object*/
assertThat(testedString, not(expectedString));
/**allOf匹配符斷言符合所有條件,相當(dāng)于“與”(&&)*/
assertThat(testedNumber, allOf( greaterThan(8), lessThan(16) ) );
/**anyOf匹配符斷言符合條件之一,相當(dāng)于“或”(||)*/
assertThat(testedNumber, anyOf( greaterThan(16), lessThan(8) ) );
數(shù)值相關(guān)匹配符
/**closeTo匹配符斷言被測的浮點(diǎn)型數(shù)testedDouble在20.0¡À0.5范圍之內(nèi)*/
assertThat(testedDouble, closeTo( 20.0, 0.5 ));
/**greaterThan匹配符斷言被測的數(shù)值testedNumber大于16.0*/
assertThat(testedNumber, greaterThan(16.0));
/** lessThan匹配符斷言被測的數(shù)值testedNumber小于16.0*/
assertThat(testedNumber, lessThan (16.0));
/** greaterThanOrEqualTo匹配符斷言被測的數(shù)值testedNumber大于等于16.0*/
assertThat(testedNumber, greaterThanOrEqualTo (16.0));
/** lessThanOrEqualTo匹配符斷言被測的testedNumber小于等于16.0*/
assertThat(testedNumber, lessThanOrEqualTo (16.0));
集合相關(guān)匹配符
/**hasEntry匹配符斷言被測的Map對象mapObject含有一個鍵值為"key"對應(yīng)元素值為"value"的Entry項(xiàng)*/
assertThat(mapObject, hasEntry("key", "value" ) );
/**hasItem匹配符表明被測的迭代對象iterableObject含有元素element項(xiàng)則測試通過*/
assertThat(iterableObject, hasItem (element));
/** hasKey匹配符斷言被測的Map對象mapObject含有鍵值“key”*/
assertThat(mapObject, hasKey ("key"));
/** hasValue匹配符斷言被測的Map對象mapObject含有元素值value*/
assertThat(mapObject, hasValue(value));