Top "Hamcrest" questions

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.

How do I compare doubles using JUnit and Hamcrest?

I'm writing a unit test using JUnit and Hamcrest. I have been comparing double values using: assertThat(result, is(0.5)); However, …

java junit hamcrest
opposite of contains in hamcrest

What is the opposite of contains? List<String> list = Arrays.asList("b", "a", "c"); // should fail, because "d" …

java hamcrest
AssertEquals when list content is unordered

How would you refactor the following if the products can be returned in any order? List<Product> products = …

java junit hamcrest
Mockito/JMockit & Hamcrest matchers : How to verify Lists/Collections?

This 2013 post on SO asked how to use Hamcrest matchers to verify lists/collections invocations in Mockito. The accepted solution …

java generics mockito jmockit hamcrest
Matching multiple properties in one Matcher

I need to write Matcher which will check multiple properties. For single property i've used: import static org.hamcrest.Matchers.…

java mockito matcher hamcrest
Android - espresso - clicking on a listview entry based on custom objects

Espresso is used for automatic testing my App. Edit: below you find a number of answers! How can I click (…

android hamcrest android-espresso
Is there a way to do deep comparison on a nested property with Hamcrest

I use hamcrest for most of my testing ,but have encountered a issue with it not being able to test …

java unit-testing hamcrest
How to use (primitive) autoboxing/widening with Hamcrest?

I came across https://code.google.com/p/hamcrest/issues/detail?id=130 to add some sugar syntax for Hamcrest matchers. …

java autoboxing hamcrest
Check output of JsonPath with Hamcrest Matchers

I wrote Spring controller Junits. I used JsonPath to fetch all IDs from JSON using ["$..id"]. I have following as …

java junit spring-test hamcrest jsonpath
How to compile Kotlin unit test code that uses hamcrest 'is'

I want to write a unit test for my Kotlin code and use junit/hamcrest matchers, I want to use …

unit-testing junit kotlin hamcrest