hamcrest

junit中的assert方法全部放在Assert类

元气小坏坏 提交于 2019-11-26 14:44:42
junit中的assert方法全部放在Assert类中,总结一下junit类中assert方法的分类。 1.assertTrue/False([String message,]boolean condition); 判断一个条件是true还是false。感觉这个最好用了,不用记下来那么多的方法名。 2.fail([String message,]); 失败,可以有消息,也可以没有消息。 3.assertEquals([String message,]Object expected,Object actual); 判断是否相等,可以指定输出错误信息。 第一个参数是期望值,第二个参数是实际的值。 这个方法对各个变量有多种实现。在JDK1.5中基本一样。 但是需要主意的是float和double最后面多一个delta的值。 4.assertNotEquals([String message,]Object expected,Object actual); 判断是否不相等。 第一个参数是期望值,第二个参数是实际的值。 5.assertArrayEquals([java.lang.String message,] java.lang.Object[] expecteds, java.lang.Object[] actuals) ; 6.assertNotNull/Null([String

How do I assert an Iterable contains elements with a certain property?

萝らか妹 提交于 2019-11-26 09:29:40
问题 Assume I want to unit test a method with this signature: List<MyItem> getMyItems(); Assume MyItem is a Pojo that has many properties, one of which is \"name\" , accessed via getName() . All I care about verifying is that the List<MyItem> , or any Iterable , contains two MyItem instances, whose \"name\" properties have the values \"foo\" and \"bar\" . If any other properties don\'t match, I don\'t really care for the purposes of this test. If the names match, it\'s a successful test. I would

Hamcrest compare collections

你离开我真会死。 提交于 2019-11-26 06:30:04
问题 I\'m trying to compare 2 lists: assertThat(actual.getList(), is(Matchers.containsInAnyOrder(expectedList))); But idea java: no suitable method found for assertThat(java.util.List<Agent>,org.hamcrest.Matcher<java.lang.Iterable<? extends model.Agents>>) method org.junit.Assert.<T>assertThat(T,org.hamcrest.Matcher<T>) is not applicable (no instance(s) of type variable(s) T exist so that argument type org.hamcrest.Matcher<java.lang.Iterable<? extends model.Agents>> conforms to formal parameter

java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing

本小妞迷上赌 提交于 2019-11-26 04:45:36
问题 While running junit test in eclipse I am getting this Exception : java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing I\'ve added junit.jar library file. I\'ve tried different versions of junit.jar: 4.4 , 4.8 , etc. How do I fix this Exception? 回答1: Add hamcrest-all-X.X.jar to your classpath . Latest version as of Feb 2015 is 1.3: http://code.google.com/p/hamcrest/downloads/detail?name=hamcrest-all-1.3.jar&can=2&q= 回答2: According to the JUnit GitHub team website (https://github.com

Getting “NoSuchMethodError: org.hamcrest.Matcher.describeMismatch” when running test in IntelliJ 10.5

ぐ巨炮叔叔 提交于 2019-11-26 04:10:02
问题 I\'m using JUnit-dep 4.10 and Hamcrest 1.3.RC2. I\'ve created a custom matcher that looks like the following: public static class MyMatcher extends TypeSafeMatcher<String> { @Override protected boolean matchesSafely(String s) { /* implementation */ } @Override public void describeTo(Description description) { /* implementation */ } @Override protected void describeMismatchSafely(String item, Description mismatchDescription) { /* implementation */ } } It works perfectly fine when run from the