Hello,
I am relatively new to matchers. I am toying around with hamcrest in combination with JUnit and I kinda like it.
Is there a way, to state that one of multiple choices is correct?
Something like
assertThat( result, is( either( 1, or( 2, or( 3 ) ) ) ) ) //does not work in hamcrest
The method I am testing returns one element of...
I'm hitting a road block and I'm wondering if the brilliant collective minds here can help. In ObjC CocoaTouch I'm trying to mock an object that takes struct parameters and returns a struct. OCMock is coughing up a hair-ball so I tried wrapping with a Hamcrest matcher. No die. The function/method I'm testing looks something like this:
-...
What's the difference between Hamcrest 1.1 and 1.2? I couldn't find a release notes page or a file listing changes! Where can I find such info?
...
Why does this not compile, oh, what to do?
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.hasItems;
ArrayList<Integer> actual = new ArrayList<Integer>();
ArrayList<Integer> expected = new ArrayList<Integer>();
actual.add(1);
expected.add(2);
assertThat(actual, hasItems(expected));
error copi...
Has anyone integrated Hamcrest with TestNG so that its matchers can easily be used in TestNG assertions?
...
Ok, I'm frustrated! I've hunted around for a good number of hours and am still stumped.
Environment: WinXP, Eclipse Galileo 3.5 (straight install - no extra plugins).
So, I have a simple JUnit test. It runs fine from it's internal Eclipse JUnit run configuration. This class has no dependencies on anything. To narrow this problem do...
When I look at the examples in the Assert class JavaDoc
assertThat("Help! Integers don't work", 0, is(1)); // fails:
// failure message:
// Help! Integers don't work
// expected: is <1>
// got value: <0>
assertThat("Zero is one", 0, is(not(1))) // passes
I dont see a big advantage over, let's say, assertEquals( 0, 1 ).
It's nice may...
Clearly the hamcrest Java library has a stable release, but as far as I can tell the hamcrest-php, hamcrest-python and hamcrest-as3 (and presumably others, but those are the ones I care about at the moment) do not; you can only acquire them in source code form. This is, putting it mildly, a bit of a pain when I have to deploy a versione...
Trying to compile this code
import static org.hamcrest.Matchers.is;
import static org.hamcrest.number.OrderingComparison.lessThan;
...
Assert.assertThat(0, is(lessThan(1)));
issues this compilation error:
assertThat(Object,
org.hamcrest.Matcher<java.lang.Object>)
cannot be applied to (int,
org.hamcrest.Matcher<capture<? su...
I'm interested in both xpath matching and full document comparisons:
assert_that(mydoc, hasTextAtXPath('/foo/bar', 'text'))
assert_that(mydoc, matchesStructurally('<some_xml/>'))
Does any matcher library exist for this? If not, what is the best place to start with for this type of comparison, so that I can write one of my own?
...
Hello!
Is there a matcher in Hamcrest to compare collections for equality?
There is contains and containsInAnyOrder but I need equals not bound to concrete collection type.
E.g. I cannot compare Arrays.asList and Map.values with Hamcrest equals.
Thanks in advance!
...
Does any matcher libraries exist for .net?
I am talking about a library like the hamcrest library for java...
...
Hello all,
I'd like to use hamcrest to assert that two maps are equal, i.e. they have the same set of keys pointing to the same values.
My current best guess is:
assertThat( affA.entrySet(), hasItems( affB.entrySet() );
which gives:
The method assertThat(T, Matcher) in the type Assert is not applicable for the arguments (Set>, M...
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 the IList class doesn't support for each iteration; for example, with the above list, this...
I sat down to write a matcher today and decided to take a quick look at the jmock documentation to refresh my memory on the process, and noticed a reference to the org.hamcrest.Factory annotation. The documentation for the annotation states.
Marks a Hamcrest static factory method so tools recognise them. A factory method is an equiv...
Hello,
i try to compare two lists with each other:
ListA (a1,a2,a3,...)
ListB (b1,b2,b3,...)
I want that a1 is compared to b1, a2 to b2, a3 to b3, ....
But i have to use another method and cannot use .equals!
I have written my own hamcrest matcher. But i have to use a for loop to iterate over the elements. is there a better solutio...
Hey,
I was wondering if anyone knew of a way to check if a List is empty using assertThat() and Matchers?
Best way I could see just use JUnit:
assertFalse(list.isEmpty());
But I was hoping that there was some way to do this in Hamcrest.
Thanks!
...
I'm writing some matchers using the Hamcrest 1.2 library, but I'm having a hard time with Java wildcards. When I try to compile the following code
public class GenericsTest {
public void doesNotCompile() {
Container<String> container = new Container<String>();
// this is the desired assertion syntax
assertT...
Hi,
We upgraded to Xcode 3.2.4 with iOS 4.1 SDK, now our tests are failing.
First because of this An internal error occurred when handling command output: -[XCBuildLogCommandInvocationSectionRecorder endMarker]: unrecognized selector sent to instance 0x201aa7200 then we used the patch suggested by apple forums (http://gist.github.com/...
In every version of JUnit I have tried (up to 4.8.1), a failing assertThat will display an error message that looks like:
expected: [describeTo]
got: [String representation of object]
In other words, it will display the toString() of the object instead of the mismatch description from the Matcher. If I use the assertThat from org.hamc...