hamcrest Questions

4

Solved

I want to be able to make unit tests and instrumentation tests in Android Studio, and using Mockito in them. I'm using the new approach for tests in Android Studio 0.8. This is: building with gr...
Araceli asked 18/8, 2014 at 16:49

1

I have an android project, which have an custom object array list, now I want to filter that array list. But always I get zero (size of new array list). public static <T> List<T> filte...
Lanate asked 14/3, 2016 at 13:25

2

I need to write Matcher which will check multiple properties. For single property i've used: import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasProperty; import or...
Disentitle asked 16/2, 2016 at 15:52

2

Solved

I want to do an assertion where the actual value is within either a fixed +/- value of the expected value or a percent +/- value of the expected value. While googling I noticed that NUnit had a n...
Jaquelinejaquelyn asked 28/10, 2014 at 18:31

3

I am trying to make use of a custom matcher from hamcrest within the hasItem matcher @Test public void populatesChildCompanies() { final long firstChildId = 2; final String firstChildName = "j...
Sgraffito asked 30/11, 2011 at 13:35

4

I am writing a lot JUnit tests these days for a legacy system. Often I come to the question: What is the best way to assert complex Objects? Here is my current code public class SomeParserTest {...
Cower asked 30/12, 2015 at 14:19

4

Solved

Is there a way in Hamcrest to compare a number within a number range? I am looking for something like this: assertThat(50L, is(between(12L, 1658L)));
Untie asked 8/10, 2012 at 14:2

3

I have an alert dialog that displays a number of items. private String[] choices; // populated externally AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setItems...
Cheyney asked 22/5, 2014 at 3:35

2

Solved

Consider the following test case using standard JUnit asserts and hamcrest's assertThat: byte b = 0; int i = 0; assertEquals(b, i); // success assertThat(b, equalTo(i)); // java.lang.AssertionErr...
Bouffant asked 26/11, 2015 at 15:6

1

Solved

Hamcrest provides a number of matchers for asserting the contents of a collection. All of these cases pass: Collection<String> c = ImmutableList.of("one", "two", "three"); assertThat(c, hasI...
Selfsatisfied asked 21/11, 2015 at 6:41

1

I'd like to test if a java.time.LocalDate is within a fixed number of days of a test date and I'd like to use Hamcrest matchers if possible. Are there any matchers for Hamcrest (java) for wor...
Demagnetize asked 15/10, 2015 at 16:14

3

Solved

Espresso is used for automatic testing my App. Edit: below you find a number of answers! How can I click (within an automated Espresso test script) on an entry in a long list of custom objects? ...
Troposphere asked 18/8, 2014 at 7:54

2

Solved

I was shocked when something along the lines of: assertThat(null, either(is(nullValue())).or(notNullValue())); Fails with: java.lang.AssertionError: Expected: (is null or not null) but: was n...
Clinandrium asked 24/9, 2015 at 10:59

3

Solved

I'm trying to find a way to test my entity using Mockito; This is the simple test method: @Mock private EntityManager em; @Test public void persistArticleWithValidArticleSetsArticleId() { Artic...
Milewski asked 15/11, 2014 at 12:35

3

Solved

I am trying to access a button from a specific view. The same view is displayed 6 times. This is the code I am using. public void testTimeConfig(){ onData(withDesc("description")).onChil...
Swallow asked 30/12, 2013 at 22:30

3

I found Hamcrest convenient to use with JUnit. Now I am going to use ScalaTest. I know I can use Hamcrest but I wonder if I really should. Does not ScalaTest provide similar functionality ? Is ther...
Illailladvised asked 14/7, 2013 at 4:55

2

How can I use mockery and hamcrest to assert that when a method of a mock object is called, one of the arguments passed to it is an array containing a key/value pair? For example, my test code mig...
Reactivate asked 19/8, 2015 at 13:47

2

I'm writing unit tests for IM- and exporting files. I need to test the resulting directory recursively byte by byte. I implemented a routine for flat directories by myself and know how to do this r...
Spallation asked 4/8, 2015 at 8:10

4

Solved

By default, the required version of Hamcrest for: JUnit 4.11 Hamcrest 1.3 Mockito-core 1.9.5 Hamcrest 1.1 There were not insiginifcant API changes between Hamcrest 1.1 and 1.3. Currently my...
Nye asked 12/9, 2013 at 17:43

3

The matcher IsIterableContainingInAnyOrder has two overloads for the static factory method containsInAnyOrder (both have the return type Matcher<java.lang.Iterable<? extends T>>): con...
Letterhead asked 4/9, 2013 at 13:2

3

Solved

I want to create a class that can run a method until a condition about the return value is fulfilled. It should look something like this methodPoller.poll(pollDurationSec, pollIntervalMillis) ...
Arrearage asked 22/6, 2015 at 20:49

5

Solved

Given a list of objects I'd like to test that they return in the correct order, but I would like to not assert the entire object. For example I'd like to verify that they're in order by id 1, id...
Honaker asked 2/6, 2015 at 17:18

2

Solved

Let's say I have a Map: Map<String,Object> map1 = new HashMap<String,Object>(); map1.put("foo1","foo1"); map1.put("foo2", Arrays.asList("foo2","bar2")); Now I'd like to use Hamcrest ...
Nichol asked 13/5, 2015 at 15:49

1

After upgrading to Java 8. I now have compile errors of the following kind: The method with(Matcher<Object>) is ambiguous for the type new Expectations(){} It is caused by this method call...
Nictitate asked 6/5, 2015 at 21:20

3

Solved

Examine the following snippet: assertThat( Arrays.asList("1x", "2x", "3x", "4z"), not(hasItem(not(endsWith("x")))) ); This asserts that the list doesn't have an element that doesn't end with...
Stochmal asked 12/5, 2011 at 23:18

© 2022 - 2024 — McMap. All rights reserved.