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

LambdaJ: matching on fields of the same object

Can someone get me out of LambdaJ pit I fell into please? let's assume I have a list of objects of this class: private class TestObject { private String A; private String B; //gettters and setters } Let's say I want to select the…
artur
  • 1,710
  • 1
  • 13
  • 28
0
votes
2 answers

Use Hamcrest's assertThat with several objects in one line?

Can I use Hamcrest's assertThat to assert something about several objects in one line of code? The objects are not in a collection. For instance, I would like to assertThat four strings are equal. Also, how can I assert that all objects are null?
0
votes
1 answer

Assert that Collection contains 2 Objects with same property using matchers

I have the following scenario, where I want to test someFunction(): Collection objects = someFunction(someInput); assertThat(objects , contains(hasProperty("property", is(propertyIWantToTest)))); This works fine if Collection
fvdalcin
  • 1,047
  • 1
  • 8
  • 26
0
votes
2 answers

How do I get the class of a Matcher in Hamcrest?

I've got a matcher, and I want to make sue the object I have is the right type. E.g. a long or a String. void expect(String xpath, Matcher matcher) { String actual = fromXpath(xpath); // convert actual into correct type for matcher …
Alex Collins
  • 980
  • 11
  • 23
0
votes
1 answer

Hamcrest JDK7 migration

Hi I try to migrate project to java 7 (JDK1.7.0_21) from java 6. On one test I noticed failures. Update: I debugged the problem. I got to ReflectiveTypeFinder.findExpectedType. public Class findExpectedType(Class fromClass) { for (Class c…
Waldemar Wosiński
  • 1,490
  • 17
  • 28
0
votes
1 answer

Dependencies for jUnit 4.11 with JMock 2.6 and Hamcrest 1.3

I'm using a combination of JUnit 4.8 JMock 2.5.1 and Hamcrest 1.1. Now I wanna upgrade to jUnit 4.11 with JMock 2.6 and Hamcrest 1.3. Cause JUnit 4.11 comes with hamcrest 1.3. I only import JUnit 4.11 and JMock trough my dependency…
user558213
  • 69
  • 1
  • 5
0
votes
2 answers

Open source spring MVC aplication with Junit tests?

Soon we will be starting a new project. It will be Spring MVC based web application. For the first time we have decided to start writing tests in the application. We will be using Junit, Mockito and Hamcrest for writing tests. Since this will be…
ajm
  • 12,863
  • 58
  • 163
  • 234
0
votes
2 answers

Is there a python hamcrest matcher library for performing XML document matching?

I'm interested in both xpath matching and full document comparisons: assert_that(mydoc, hasTextAtXPath('/foo/bar', 'text')) assert_that(mydoc, matchesStructurally('')) Does any matcher library exist for this? If not, what is the best…
Chris R
  • 17,546
  • 23
  • 105
  • 172
0
votes
1 answer

OpenKinect wrapper in Java

I'm trying to use OpenKinect's wrapper in Java from this address: https://github.com/OpenKinect/libfreenect/tree/master/wrappers/java I've also added the jna-3.0.9.jar, hamcrest-all-1.3.jar, and junit-4.8.jar to the project, so now everything is…
user1191284
0
votes
2 answers

Using Hamcrest's hasKeyValuePair with laravel's unit test

I have the following test: public function testTestNameRequired(){ Validator::shouldReceive("make")->once() ->with(array(1,2,3), hasKeyValuePair("name",array("required"))) ->andReturn(m::mock(["passes"=>true])); $r =…
jasonlfunk
  • 5,159
  • 4
  • 29
  • 39
0
votes
2 answers

How to write Matchers that match Matchers matching stuff

Ok, so I want to test my shiny new hamcrest Matchers. Are there any Matchers that match custom Matchers matching or not matching stuff? This would greatly help with writing tests for custom Matchers.
kungfoo
  • 1,297
  • 1
  • 14
  • 27
0
votes
1 answer

What is the right way to compare as3 objects using hamcrest

I'm trying to compare two objects to see if they are the same using hamcrest for flex-unit, but when the object has sub objects, it just throws an error: Error: Expected: (An array containing <[object Object]> but: an array containing <[object…
Marcotmp
  • 71
  • 7
0
votes
2 answers

How to return type I explicitly passed as parameter?

I want to store a type as parameter, but when I return it and check in within a JUnit test, I get something like Expected: an instance of Java.lang.String but: is a java.lang.class This is a minimalized example of the…
Bevor
  • 8,396
  • 15
  • 77
  • 141
0
votes
2 answers

Hamcrest hasItem and Mockito verify inconsistency

I've ran into an issue with hamcrest and mockito. Here is what I'm trying to do: public class A{ public void foo(List arg){ return; } } public BMatcher extends BaseMatcher{ //Some impl... } In my test I want to do…
0
votes
3 answers

Python Hamcrest - test that list is not empty

Is there a clean way to test that a list is not empty in Hamcrest (python). There are several ways to do it by checking the list length etc., but I'd like something that reads nicely for tests.
Stefan
  • 8,819
  • 10
  • 42
  • 68