Questions tagged [hamcrest]

Hamcrest is an open source library of constraint classes used to match objects and values, typically by other frameworks such as unit testing, mocking, or collections.

Hamcrest has been ported to Java, C++, Objective-C, Python, PHP and Erlang.

It is included as part of JUnit to make assertions more readable (It is also called fluent API). Compare

assertNotEquals(-1, userName.indexOf("bob"));

to

assertThat(userName, containsString("bob"));
710 questions
0
votes
1 answer

Can't find assertThat

Here is my code import org.junit.Test; import static org.junit.Assert.assertThat; import static sun.nio.cs.Surrogate.is; public class PlayerTest { public void should_return_3_when_status_is_3(){ Player player = new Player(); …
Shihe Zhang
  • 2,641
  • 5
  • 36
  • 57
0
votes
2 answers

Assertion, is null or is an instance of specific Class

simple I thought Assert.assertThat( iterator.next(), Matchers.either(Matchers.nullValue()).or( Matchers.instanceOf(Double.class))); So I'd like to ensre next() returns one of two, NULL or…
wilu
  • 549
  • 1
  • 12
  • 26
0
votes
2 answers

Writing better JUnit Parameterized test cases

I have an interesting requirement. I want to have as better test case coverage as possible in my application. I am using Parameterized Junit to run testcases with number of different inputs. My sample test class looks like this: @Parameters public…
Kevindra
  • 1,682
  • 3
  • 24
  • 45
0
votes
2 answers

Non-serializable Matcher in Wicket Behavior

I was building a visibility behavior on Wicket that used Hamcrest Matcher (and some Lambdaj) to see if any of the given property models values match the given matcher and if so, then it would hide the component. public class…
vertti
  • 7,539
  • 4
  • 51
  • 81
0
votes
1 answer

Why does this hamcrest matcher work in eclipse but not outside?

Possible Duplicate: Hamcrest's hasItems I've written a test using a hamcrest matcher that looks like: @Test public void testGenericsIsEmpty() { List myStrings = new LinkedList(); …
Jeff Storey
  • 56,312
  • 72
  • 233
  • 406
0
votes
2 answers

Case Insensitive filtering with lambdaj

I'm attempting to familiarize myself with lambdaj, and am unsure how the best way to solve this problem. Given the following test: @Test public void test() { final List l1 = new ArrayList<>(); final List l2 = new…
Scott
  • 9,458
  • 7
  • 54
  • 81
0
votes
2 answers

Testing collection equality with ordering

I'm writing simple test which checks method returning some of interface beneath Collection. I'm trying to abstract internal representation of this collection as much as possible, so that this test will pass in both cases: when method returns List…
Mateusz Chromiński
  • 2,742
  • 4
  • 28
  • 45
-1
votes
1 answer

Fix for the message "The method empty() is undefined for the type JunitAssertions"

I'm working with Junit Assertions. I'm facing problems when using assertThat. Below code shows that the 'assertThat' has been strike off. Also whatever matcher i use like empty, is, equalsTo i get error message as 'The method empty() is undefined…
-1
votes
1 answer

No value at JSON path $[0].nom?

I'm currently developping a rest api web service and i have to test them using unit testing, so i cannot figure out how to test the RESTFul API with Spring using Mockito and Junit, first of all i have preapared the class in which i created two…
Hamza Khadhri
  • 207
  • 4
  • 19
-1
votes
1 answer

How to add `hamcrest-core-1.3.jar` to the classpath variable in windows?

My classpath is linked to junit home which contains both hamcrest-core-1.3.jar and junit-4.12.jar. The junit seems to be recognized but I'm getting a NoClassDefFoundError: org/hamcrest/SelfDescribing. I think I have to link the hamcrest to the…
Makdessi
  • 3
  • 2
-1
votes
2 answers

Cannot import assertThat method junit

I am using hamcrest and junit to perform the tests, I need to compare 2 maps that have the same items but in different order, so assertEquals does not work for me. I have already seen the answers that have been put to that, but I have not been able…
kmilo93sd
  • 791
  • 1
  • 15
  • 35
-1
votes
1 answer

Does Hamcrest contain test runner or should I use a runner from another framework?

I've found only Hamcrest assertions in Hamcrest project. Tests in the applications I saw are run with JUnit runner. Is there a way to run tests with Hamcrest or is Hamcrest not for this?
Diamond
  • 217
  • 1
  • 3
  • 7
-1
votes
1 answer

Mockito Invalid use of matchers Mock(Object.class) & anyString()

Ola, I'm busy writing a unit test like monitor.severe(mock(MonitorEventType.class), anyString()); When I execute this I get: Invalid use of argument matchers. 0 matchers expected, 1 recorded. So I…
Bgvv1983
  • 1,256
  • 1
  • 13
  • 27
-1
votes
1 answer

Unit test being confused by three question marks

Im writing some junits, and have this check, comparing the keys and values of two hashmaps Iterator> it = expected.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = (Map.Entry
scphantm
  • 4,293
  • 8
  • 43
  • 77
-1
votes
1 answer

Groovy - how to match (assert) that a certain value is contained in an array of expected values

I have a script which checks returned http status codes. import static org.hamcrest.Matchers.anyOf import static org.hamcrest.Matchers.equalTo import static org.hamcrest.MatcherAssert.assertThat int[] expectedStatuses = [201,204] def pollStatusCode…
Honza Sestak
  • 115
  • 1
  • 2
  • 8
1 2 3
47
48