Issue
I'm using method presented below to validate if Activity I'm testing starts another activity.
Instrumentation.addMonitor (IntentFilter filter, Instrumentation.ActivityResult result, boolean block)
According to documentation, block parameter controls whether the monitor should block the activity start (returning its canned result). And this is what I want to achieve - I want to return the AcitivityResult back to calling activity: onActivityResult(). Code I use is listed below:
Intent resultIntent = new Intent();
Bundle bundle = new Bundle();
bundle.putLong(ActivityBundleKeys.KEY_TEST, 2L);
resultIntent.putExtras(bundle);
ActivityResult result = new ActivityResult(Activity.RESULT_OK, resultIntent);
ActivityMonitor monitor = mInstr.addMonitor(MapViewActivity.class.getName(), result, true);
mSolo.clickOnView(btnMap); //button properly clicked, activity started
Activity currentActivity = mInstr.waitForMonitor(monitor);
If I understand correctly, if I pass "true" to the addMonitor(), starting should be blocked and my calling activity should receive mocked result. It's not happening. Requested activity starts normally, and is visible in emulator. Result is not returned to calling activity. Anyone had similar problem with that?
Solution
Ok, I manage to solve this by manually returning mocked intent:
Intent resultIntent = new Intent();
Bundle bundle = new Bundle();
bundle.putLong(ActivityBundleKeys.KEY_TEST, 2L);
resultIntent.putExtras(bundle);
ActivityResult result = new ActivityResult(Activity.RESULT_OK, resultIntent);
//Don't know why, but "result" parameter in below call is not used
ActivityMonitor monitor = mInstr.addMonitor(MapViewActivity.class.getName(), result, true);
mSolo.clickOnView(btnMap);
Activity currentActivity = mInstr.waitForMonitor(monitor);
currentActivity.setResult(Activity.RESULT_OK, resultIntent);//manually seting the returned intent
currentActivity.finish();
mInstr.waitForIdleSync();
Answered By - Ramps
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.