Reputation: 14831
I am developing an Android application using Kotlin. I am adding instrumented tests to my application. I am having a problem testing the background of textview if it's right drawable set in XML resource.
I am setting the background of the text view programmatically like this.
when (type) {
ApplicationController.EVENT_TYPE_FUTURE -> {
detailsViewHolder.tvStatus.setBackgroundResource(R.drawable.background_future_event)
}
ApplicationController.EVENT_TYPE_PAST -> {
detailsViewHolder.tvStatus.setBackgroundResource(R.drawable.background_past_event)
}
ApplicationController.EVENT_TYPE_CURRENT -> {
detailsViewHolder.tvStatus.setBackgroundResource(R.drawable.background_current_event)
}
}
In the expresso, I want to assert that the text view is set with the right XML resource. How can I do that?
Upvotes: 1
Views: 887
Reputation: 3894
You could use one of the Espresso's view matchers ViewMatchers.hasBackground:
onView(withId(R.id.tvStatus)).check(matches(hasBackground(R.drawable.background_future_event)))
Although the matcher is in beta, but I hope it works in your case, otherwise you may have to create a custom matcher.
Upvotes: 2