Is there any good way to test the result code and data in an Android Espresso test? I am using Espresso 2.0.
Suppose I have an Activity
called BarActivity.class
, which upon performing some action, calls setResult(int resultCode, Intent data)
with the appropriate payload.
I'd like to write a test case to verify the resultCode
and data
. However, because setResult()
is a final
method, I can't override it.
Some options I thought about were:
- Define a new method like
setActivityResult()
and just use that so it can be intercepted, etc... - Write a test-only TestActivity that will call
startActivityForResult()
onBarActivity
and check the result inTestActivity.onActivityResult()
Trying to think what's lesser of the two evils, or if there's any other suggestions on how to test for this. Any suggestions? Thanks!