hamcrest Questions
4
Solved
I have a scenario where I receive a list from a method call and I would like to assert that the list contains the correct elements. One way to do this would be to look for some detail in each eleme...
Parathyroid asked 29/11, 2017 at 19:20
4
Solved
I have a method that will return a list of objects of type MyClass. MyClass has many properties, but I care about type and count. I want to write a test that asserts that the returned list contains...
Watanabe asked 8/10, 2018 at 1:15
4
Solved
I have a piece of code in a test that checks that a list of results contains certain properties, using Hamcrest 2.2:
assertThat(result.getUsers(), hasItem(
hasProperty("name", equalTo(us...
Sexed asked 7/4, 2021 at 8:45
16
Solved
I tried updating a Laravel project I'm working on today using composer update
But it hung on Updating dependencies (including require-dev)
So I tried things like updating composer, dump-autoload,...
Ilke asked 14/9, 2015 at 21:4
3
Solved
hasProperty can be used with hasItem to check for the value of a given property, eg:
Matcher hasName = Matchers.<Person>hasProperty("name", is("Winkleburger"));
assertThat...
10
Solved
Assume I want to unit test a method with this signature:
List<MyItem> getMyItems();
Assume MyItem is a Pojo that has many properties, one of which is "name", accessed via getName().
All I...
Longrange asked 28/8, 2012 at 19:43
4
Solved
I have an API endpoint which, when called with GET, returns an array of JSON objects in the body, like this:
[
{"id": "321", "created": "2019-03-01", "updated": "2019-03-15"},
{"id": "123", "cre...
Krugersdorp asked 20/3, 2019 at 19:45
21
While running junit test in eclipse I am getting this Exception:
java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
I've added junit.jar library file.
I've tried different versions of ...
Herbert asked 26/1, 2013 at 16:41
4
Solved
I'm writing a unit test using JUnit and Hamcrest. I have been comparing double values using:
assertThat(result, is(0.5));
However, I'm now needing to compare calculated values and I don't want t...
4
For example, I have JSON in response:
[{"id":1,"name":"text"},{"id":2,"name":"text"}]}
I want to verify if a response contains a custom object. For example:
Person(id=1, name=text)
I found s...
Flanch asked 16/3, 2018 at 15:43
3
Solved
List<String> expectedStrings = Arrays.asList("link1", "link2");
List<String> strings = Arrays.asList("lalala link1 lalalla", "lalalal link2 lalalla");
For each expectedString, I need ...
5
Solved
I use hamcrest for most of my testing ,but have encountered a issue with it not being able to test a property one level down in the object graph .A snipped of my test case is below
final List<F...
Presuppose asked 1/4, 2016 at 18:26
24
Solved
I am using hamcrest 1.3 to test my code. It is simply a die. I am trying to test it to make sure the number generated is less than 13. I had a print statement that printed what the number generated...
4
The following statement does not work because doesNotExist() returns a ViewAssertion instead of a matcher. Any way to make it work without a try-catch?
.check(either(matches(doesNotExist())).or(m...
Cardsharp asked 23/12, 2016 at 8:4
5
I'm trying to write some integration tests in my Spring Boot application using REST-Assured and JUnit5 but when I run the following:
@SpringBootTest(classes = ProductsApplication.class)
class Prod...
Dynamics asked 29/1, 2020 at 9:9
3
Solved
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
...
3
Solved
import static org.junit.matchers.JUnitMatchers.both;
import static org.junit.matchers.JUnitMatchers.containsString;
Now I check it contains foo and bar as below ...
Assert.assertThat(text,
both(...
5
For several days I am using now Junit's Matchers feature. Everything is working OK but I am looking for a matcher which uses a comparator for comparing and which does not rely on the objects equals...
7
Solved
I'm running into a generics problem with Mockito and Hamcrest.
Please assume the following interface:
public interface Service {
void perform(Collection<String> elements);
}
And the foll...
6
Solved
I'm currently trying to build a more or less complete set of unit tests for a small library. Since we want to allow different implementations to exist we want this set of tests to be (a) generic, s...
Titer asked 3/7, 2009 at 14:51
2
Solved
I came across https://code.google.com/p/hamcrest/issues/detail?id=130 to add some sugar syntax for Hamcrest matchers. But the idea was rejected by the Hamcrest developers.
Any other smart ideas to...
Everglades asked 18/10, 2014 at 8:40
3
Solved
Using the hamcrest library for Java, what's a nicely readable way to do the opposite of:
assertThat(someCollection, hasItem(someItem))
I want to make sure someCollection does not contain item so...
4
Solved
I have a unit test that needs to check for a nested map value. I can get my assertion to work by pulling out the entry and matching the underlying Map, but I was looking for a clear way to show wha...
5
Solved
I use the following code at the moment to assert on a boolean value, however the method org.hamcrest.Matchers.is() is deprecated.
assertThat(someValue, is(false));
Is there a simple alternative ...
Whom asked 26/9, 2012 at 16:23
3
We have a function which takes a variety of different types of input: a function, a string, a compiled regular expression, a Hamcrest Matcher, and filters a list appropriately based on the type of ...
Collected asked 6/6, 2013 at 14:17
1 Next >
© 2022 - 2024 — McMap. All rights reserved.