Fixed
Status Update
Comments
ku...@google.com <ku...@google.com>
ku...@google.com <ku...@google.com> #2
Thank you for reporting this issue. For us to further investigate this issue, please provide the following additional information:
Android build
Which Android build are you using? (e.g. OPM1.171019.011)
Device used
Which device did you use to reproduce this issue?
Steps to reproduce
Please provide a sample application or apk to reproduce the issue.
Also kindly mention the steps to be followed for reproducing the issue with the given sample application.
Expected output
Could you please explain the expected behavior.
Current output
Could you please explain the current behavior.
Android build
Which Android build are you using? (e.g. OPM1.171019.011)
Device used
Which device did you use to reproduce this issue?
Steps to reproduce
Please provide a sample application or apk to reproduce the issue.
Also kindly mention the steps to be followed for reproducing the issue with the given sample application.
Expected output
Could you please explain the expected behavior.
Current output
Could you please explain the current behavior.
nk...@google.com <nk...@google.com>
ma...@gmail.com <ma...@gmail.com> #3
Hello,
Android build:
API27 emulator image
Device used:
API27 emulator image
Steps to reproduce:
Download this PoC project:https://github.com/julioromano/ActivityTestRuleBugPoC
The repository includes one test class with two test methods.
One succeeds the other fails because of a configuration change.
Expected output
MainActivityTest.rotateAndFinishWithResult() should not fail.
Current output
MainActivityTest.rotateAndFinishWithResult() fails because after the calls to .setRequestedOrientation, the active instance of MainActivity changes but ActivityTestRule keeps a reference only to the very first instance that it had launched at the beginning of the test.
This means the call rule.getActivityResult(); fails because the rule is querying for result on the first instance of the activity that has been destroyed and never set a result.
Android build:
API27 emulator image
Device used:
API27 emulator image
Steps to reproduce:
Download this PoC project:
The repository includes one test class with two test methods.
One succeeds the other fails because of a configuration change.
Expected output
MainActivityTest.rotateAndFinishWithResult() should not fail.
Current output
MainActivityTest.rotateAndFinishWithResult() fails because after the calls to .setRequestedOrientation, the active instance of MainActivity changes but ActivityTestRule keeps a reference only to the very first instance that it had launched at the beginning of the test.
This means the call rule.getActivityResult(); fails because the rule is querying for result on the first instance of the activity that has been destroyed and never set a result.
nk...@google.com <nk...@google.com> #4
This will be fixed in the upcoming Runner/Rules v1.0.2 release.
nk...@google.com <nk...@google.com> #5
The release is not out yet but marking this as fixed for now.
Description
Version used: "1.0.1"
What steps will reproduce the problem?
Test an `Activity`'s `setResult()` using `ActivityTestRule.getActivityResult()` and Espresso.
If the activity undergoes a configuration change (such as display rotation) during the test, `ActivityTestRule.getActivity()` will still return the previous instance of the activity (the one existing before the configuration change). This will make any subsequent calls to `ActivityTestRule.getActivityResult()` throw `IllegalStateException` with error message: "Activity is not finishing!".
Example code snippet:
@Rule
public ActivityTestRule<MyActivity> rule = new ActivityTestRule<>(MyActivity.class);
@Test
public void myTest() throws Exception {
rule.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Espresso.onView(ViewMatchers.withId(R.id.button)).perform(click()); // In MyActivity this button click will trigger setResult() and finish().
Instrumentation.ActivityResult result = activityTestRule.getActivityResult(); // Test will crash here.
}