Testing startActivityForResult

667 views
Skip to first unread message

Alexey Sergeev

unread,
May 6, 2016, 2:55:13 PM5/6/16
to Android Testing Support Library
Is there any way to unit test "startActivityForResult'?
I didn't find a way to automate starting activity for result and getting the result back to the test case.
Any ideas please?
Thanks a lot.

lu...@reverb.com

unread,
May 7, 2016, 3:17:22 PM5/7/16
to Android Testing Support Library
Hey Alexey,

If you're referring to testing how your activity under test responds to a result, see Espresso's Intents: https://google.github.io/android-testing-support-library/docs/espresso/intents/

If you're referring to testing that your activity returns the correct Intent and result code when it's started with startActivityForResult, we have a solution we blogged about here:

Hope that helps.

Alexey Sergeev

unread,
May 10, 2016, 10:40:53 AM5/10/16
to Android Testing Support Library, lu...@reverb.com
Thanks Luis.
It looks that the second option is my case and that is what I used to do simple tests. The problem is that the ResultTestActivity needs to be registered in the manifest file of the app and that is what we don't want to happen. I am trying to google is I can create a separate manifest file in the androidTest package and registered the activity there. Do you know if I can do that?
Thanks a lot.

lu...@reverb.com

unread,
May 10, 2016, 10:55:07 AM5/10/16
to Android Testing Support Library, lu...@reverb.com
On Tuesday, May 10, 2016 at 9:40:53 AM UTC-5, Alexey Sergeev wrote:
The problem is that the ResultTestActivity needs to be registered in the manifest file of the app and that is what we don't want to happen. I am trying to google is I can create a separate manifest file in the androidTest package and registered the activity there. Do you know if I can do that?
Thanks a lot.

You can't do that because the androidTest manifest is used for the tester application, not your main app under test.
We added it (and other test helper activities) to our debug/ manifest. Then at least it doesn't get in the final prod build.

Hope that helps!

Alexey Sergeev

unread,
May 10, 2016, 10:56:57 AM5/10/16
to Android Testing Support Library, lu...@reverb.com
That could be one of the options.
Thanks.
Reply all
Reply to author
Forward
0 new messages