hamcrest

How to count RecyclerView items with Espresso

放肆的年华 提交于 2019-11-30 02:41:08
Using Espresso and Hamcrest, How can I count items number available in a recyclerView? Exemple: I would like check if 5 items are displaying in a specific RecyclerView (scrolling if necessary). nenick Here an example ViewAssertion to check RecyclerView item count public class RecyclerViewItemCountAssertion implements ViewAssertion { private final int expectedCount; public RecyclerViewItemCountAssertion(int expectedCount) { this.expectedCount = expectedCount; } @Override public void check(View view, NoMatchingViewException noViewFoundException) { if (noViewFoundException != null) { throw

Why should I use Hamcrest-Matcher and assertThat() instead of traditional assertXXX()-Methods

风流意气都作罢 提交于 2019-11-29 18:46:24
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 maybe for the messages if the constructs get more complicated but do you see more advantages? Readability? Joachim Sauer There's no big advantage for those cases where an assertFoo exists that exactly matches your intent. In those cases they behave almost the same.

Is there a Hamcrest “for each” Matcher that asserts all elements of a Collection or Iterable match a single specific Matcher?

旧街凉风 提交于 2019-11-29 16:34:11
问题 Given a Collection or Iterable of items, is there any Matcher (or combination of matchers) that will assert every item matches a single Matcher ? For example, given this item type: public interface Person { public String getGender(); } I'd like to write an assertion that all items in a collection of Person s have a specific gender value. I'm thinking something like this: Iterable<Person> people = ...; assertThat(people, each(hasProperty("gender", "Male"))); Is there any way to do this without

Ant + JUnit: NoClassDefFoundError

强颜欢笑 提交于 2019-11-29 16:08:04
问题 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 down as much as possible it simply contains: @Test public void testX() { assertEquals("1", new Integer(1).toString()); } No sweat so far. Now I want to take the super

Composer hanging while updating dependencies

China☆狼群 提交于 2019-11-29 11:19:49
问题 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, but nothing seemed to work. Then I ran it in verbose mode: composer update -vvv And I noticed it hung while reading this json: Reading path/to/Composer/repo/https---packagist.org/provider-cordoval$hamcrest-php.json from cache I tried searching for cordoval/hamcrest-php on packagist.org and couldn't

Is org.junit.Assert.assertThat better than org.hamcrest.MatcherAssert.assertThat?

徘徊边缘 提交于 2019-11-29 08:07:22
问题 I'm new to JUnit and Hamcrest and would like best-practice advice so I can decided which documentation to study first. For starters, which of these assertThat methods is better? org.junit.Assert.assertThat (from junit-4.11.jar) org.hamcrest.MatcherAssert.assertThat (from hamcrest-core-1.3.jar) According to one person last year, "JUnit has the assertThat method, but hamcrest has its own assertThat method that does the same thing.". According to someone earlier this year, Hamcrest "could

onChildView and hasSiblings with Espresso

只谈情不闲聊 提交于 2019-11-29 02:09:15
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")).onChildView(withId(R.id.positive)).perform(click()); } private static Matcher<Object> withDesc(String desc) { return allOf(is(instanceOf(String.class)), is(desc)); } When I run, I get an error: Error performing 'load adapter data' on view 'is assignable from class: class android.widget.AdapterView'. Is this the best way to access a child view? If so, how? EDIT This is the code I am trying to use now. onView(allOf(

How to count RecyclerView items with Espresso

情到浓时终转凉″ 提交于 2019-11-29 00:17:11
问题 Using Espresso and Hamcrest, How can I count items number available in a recyclerView? Exemple: I would like check if 5 items are displaying in a specific RecyclerView (scrolling if necessary). 回答1: Here an example ViewAssertion to check RecyclerView item count public class RecyclerViewItemCountAssertion implements ViewAssertion { private final int expectedCount; public RecyclerViewItemCountAssertion(int expectedCount) { this.expectedCount = expectedCount; } @Override public void check(View

Checking that a List is not empty in Hamcrest

*爱你&永不变心* 提交于 2019-11-28 16:26:31
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. skaffman Well there's always assertThat(list.isEmpty(), is(false)); ... but I'm guessing that's not quite what you meant :) Alternatively: assertThat((Collection)list, is(not(empty()))); empty() is a static in the Matchers class. Note the need to cast the list to Collection , thanks to Hamcrest 1.2's wonky generics. The following imports can be used with hamcrest 1

Why should I use Hamcrest-Matcher and assertThat() instead of traditional assertXXX()-Methods

若如初见. 提交于 2019-11-28 13:38:38
问题 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 maybe for the messages if the constructs get more complicated but do you see more advantages? Readability? 回答1: There's no big advantage for those cases where an