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
2 answers

Using espresso view matcher with hamcrest matchers

Can someone please tell me why does not this works onView(withId(R.id.edt_apikey)).check(matches(hasErrorText(anyString()))); Shows this in logcat: android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'with error:…
Pinser
  • 1,898
  • 3
  • 29
  • 43
0
votes
2 answers

How to add Hamcrest to XCODE?

I cannot find the actual hamcrest.framework - only the source code. What steps are to take to actually include into xcode ? I tried to compile the source code but do not get it connected to a new project I want to create.
Timm Kent
  • 1,123
  • 11
  • 25
0
votes
1 answer

Unable to assert that list contains a map

I want to use hamcrest to compare a list which has map entries. Map aMapWithCertainEntries = new HashMap(); aMapWithCertainEntries.put("entry1Key", "entry1Value"); aMapWithCertainEntries.put("entry2Key", "entry2Value"); …
Sathyakumar Seshachalam
  • 2,013
  • 3
  • 20
  • 32
0
votes
2 answers

Does the hamcrest library for JUnit has an API to test public variables rather than properties

I am trying to test public variables having specific values. The problem is that I am testing public variables, not JavaBean. Assert.assertThat(clientMapper.entries, Matchers.hasItem( Matchers.allOf( …
Sergei Ledvanov
  • 2,131
  • 6
  • 29
  • 52
0
votes
2 answers

using ArgumentCaptor and hamcrest.hasSize

I'm using Mockito and Hamcrest for unittesting in Java. Very often I use Hamcrests hasSize to assert some collection has a certain size. A few minutes ago, I was writing a test where I'm capturing a List of the invocation of (replaced the…
Manu
  • 1,474
  • 1
  • 12
  • 18
0
votes
2 answers

Matcher assert on two objects

I have an integration test that checks the content type of a response as follows Header header = new BasicHeader("Content-Type", "application/octet-stream; charset=UTF-8"); assertThat(response.getEntity().getContentType(),…
Lucian Enache
  • 2,510
  • 5
  • 34
  • 59
0
votes
1 answer

JSON arrays with duplicate items with Hamcrest and RestAssured

As a follow up question for my question in Dealing arrays with hamcrest and rest assured How can I use hamcrest with restassured so that I can test { "mobilenum": "+6519829340", "firstname": "Allen", "lastname": "Edwards", …
Francis Zabala
  • 1,037
  • 2
  • 11
  • 30
0
votes
1 answer

error: method addOutcome in class OutcomesTable cannot be applied to given types

When I am trying to hamcrest matcher with jbehave outcome table I am getting below compile time error at the time of maven build. "error: method addOutcome in class OutcomesTable cannot be applied to given types" please refer below sample code. …
Rajeev
  • 519
  • 3
  • 13
  • 29
0
votes
1 answer

How to notate that the parameter value doesn't matter in a JUnit test?

I'm doing some TDD using JUnit4, Mockito, and Hamcrest. My current test looks like this: FeatureFilter featureFilter = FeatureFilter .describeFeature() .addFeatureRef("myNewFeature", thatIsAvailable() …
0
votes
3 answers

What's the best way to use hamcrest-AS3 to test for membership in an IList?

I'm using Flex 3.3, with hamcrest-as3 used to test for item membership in a list as part of my unit tests: var myList: IList = new ArrayCollection(['a', 'b', 'c']).list; assertThat(myList, hasItems('a', 'b', 'c')); The problem is that apparently…
Chris R
  • 17,546
  • 23
  • 105
  • 172
0
votes
1 answer

creating a custom matcher to check exceptions in a list

I'm not sure how to create a custom matcher that would verify the information stored in a custom exception. I need a custom matcher because the way exceptions are stored in this system that I'm working on is they are added up on a list. Now I need…
chip
  • 3,039
  • 5
  • 35
  • 59
0
votes
0 answers

java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch

Assert.assertThat(newUrl.contains("providerId="), is(true)); why do i get this error: java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V at…
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
0
votes
1 answer

Multiple condition under select in LambdaJ

I'm looking to select using two conditions in LambdaJ select, i've tried to use and() function but i can't figure out how to use it.the above code selects using one condition. how i could add another condition? select(filteredPB, …
geogeek
  • 1,274
  • 3
  • 25
  • 42
0
votes
1 answer

Using hamcrest to assert that I get a collection of Objects back and that one of them has a property set to a particular value?

I just started using Hamcrest, so I'm probably doing it all wrong. I have a List foos and the Foo interface looks a bit like this: public abstract interface Foo { public String getBar(); } It is implemented by impl.FooImpl: public class…
Christian
  • 6,070
  • 11
  • 53
  • 103
0
votes
0 answers

Junit through terminal

I have a folder containing junit.jar,hamcrest-core-1.3.jar, and my java files containing the tests. I am running "javac -cp ./junit.jar: Tests.java" to compile my junit test. When I go to run my test with "java -cp ./junit.jar:.…
j_vega19
  • 228
  • 1
  • 2
  • 11