Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between bounded matcher and type safe matcher in espresso?

In android support testing library while writing test case for recyclerview some demos uses TypeSafeMatcher while other uses BoundedMatcher. Can anyone explain me why to use when with example or use case ?

like image 713
kaushal trivedi Avatar asked Sep 12 '17 22:09

kaushal trivedi


People also ask

What are the built-in matchers in espresso testing framework?

Some of the important built-in matchers useful in espresso testing framework are as follows − allOf − accept any number of matchers and matches only if all matchers are succeeded. anyOf − accept any number of matchers and matches if any one matcher succeeded. not − accept one matcher and matches only if the matcher failed and vice versa.

What is the difference between withEach matcher and withtext matcher?

Each matcher matches a particular attributes of the view and applies to particular type of view. For example, withId matcher matches the Id property of the view and applies to all view, whereas withText matcher matches the Text property of the view and applies to TextView only.

How does Bf matcher work?

It takes the descriptor of one feature in first set and is matched with all other features in second set using some distance calculation. And the closest one is returned. For BF matcher, first we have to create the BFMatcher object using cv.BFMatcher ().

What is view matcher in Eclipse framework?

Espresso framework provides many view matchers. The purpose of the matcher is to match a view using different attributes of the view like Id, Text, and availability of child view. Each matcher matches a particular attributes of the view and applies to particular type of view.


1 Answers

They are very similar. Both are a common type of matcher that you can extend and often they can be used for the same job. But there's one difference that you should always be aware of.

TypeSafeMatcher originates from the hamcrest library and is a more general type of matcher. With this type of matcher you should always check the type of whatever you are asserting against. If the type check passes (ie. view instanceOf TextView), you continue your assertions.

BoundedMatcher is a class from the Android Test Support Library and is a convenience class that does the typecheck for you.

As suggested by @humblerookie there's an excellent explanation here.

like image 88
Bohsen Avatar answered Sep 21 '22 19:09

Bohsen