While writing instrumentations tests for RecyclerView, I noticed that some demos uses TypeSafeMatcher and others use BoundedMatcher. Can anyone explain to me when to use each with an example or use case?
While writing instrumentations tests for RecyclerView, I noticed that some demos uses TypeSafeMatcher and others use BoundedMatcher. Can anyone explain to me when to use each with an example or use case?
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.