-
Notifications
You must be signed in to change notification settings - Fork 531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #2785 & Fixes part of #2743: A11y activity label added #2783
Conversation
...edTest/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityTest.kt
Outdated
Show resolved
Hide resolved
app/src/sharedTest/java/org/oppia/android/app/administratorcontrols/AppVersionActivityTest.kt
Show resolved
Hide resolved
@@ -85,6 +82,10 @@ import javax.inject.Singleton | |||
) | |||
class AppVersionActivityTest { | |||
|
|||
@get:Rule | |||
val activityScenarioRule: ActivityScenarioRule<AppVersionActivity> = | |||
ActivityScenarioRule(createAppVersionActivityIntent()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
launch function internally using ActivityScenario and calling scenario.launchInternal();
.
Currently, we use ActivityScenario and this implementation is of ActivityScenarioRule, need to check the difference as I guess there is a tiny difference between them that,
ActivityScenario doesn't clean up the state after test ends but ActivityScenarioRule does it.
Also, in the ActivityScenarioRule
, we cannot do any kind of setup before launching the activity, that's something we can do with ActivityScenario
.
So if wee move with ActivityScenario
and don't use .use{}
, then we need something like
@After
fun cleanup() {
scenario.close()
}
Need some expert points here @BenHenning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We talked about this during the team meeting today @anandwana001. I suggest looking over the team notes; there were some bits in there that were recorded from the discussion I think.
@rt4914 I'm curious about one thing: does scenario rule let us handle configuration changes correctly? I was under the impression that the scenario gets recreated when the activity does (since scenarios treat DESTROYED as a terminal state). Can you confirm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made two new commits.
Commit 9d77057 shows that config change can easily be done with ActivityScenarioRule
.
Commit d9fd298 shows that the code which we need before starting the activity also works correctly with ActivityScenarioRule
.
Overall there is an advantage of using ActivityScenarioRule
:
(a.) It can replace both ActivityTestRule
and ActivityScenario
and can provide consistency to all tests.
(b.) ActivityScenario does't clean up device state automatically and may leave the activity keep running after the test finishes. Call close() in your test to clean up the state or use try-with-resources statement. This is optional but highly recommended to improve the stability of your tests. Also, consider using ActivityScenarioRule. Reference
Limitation with ActivityScenarioRule
:
It does not allow us to change intent inside tests which we normally does for various test cases.
Solution is to use LazeActivityScenarioRule
which can allow us to change the intent for each test case. Reference
Open Questions
If we use LazeActivityScenarioRule
can this create some other type of issue?
WDYT we should do finally?
Also, I highly recommend reading this blog as it summaries the difference between ActivityTestRule
, ActivityScenario
and ActivityScenarioRule
nicely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep in mind we can't just copy LazyActivityScenarioRule--we would need to create our own rule that effectively does the same thing as ActivityScenarioRule but lets us customize the intent. I think the need here is pretty clear, but we need to define specifically what the desired API is. I suspect defaulting the intent is actually desirable for most situations, and having per-test overriding seems reasonable. However, it's not straightforward to implement that without accidentally opening multiple activities. I think we would need to start a draft PR introducing such a utility & iterate on the design a bit there to figure out something that would work for all cases. I do not recommend referencing the one from the blog--its existence introduces the idea that we can try to create on our own, but we need to be more careful about overly depending on external code that's not pre-packaged into a library.
Also, I'm not sure my original question regarding configuration changes was answered. See #2572 for specifics here--the perform orientation change doesn't actually force configuration changes in all environments (e.g. Robolectric). To answer this question, I think we need to check a test that passes in #2572 for both Espresso & Robolectric with the new utility, but also using ActivityScenarioRule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BenHenning Considering that this requires more research work now, can I pass in to @anandwana001 and focus back on A11y PRs. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, sgtm @rt4914.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @rt4914. Left some thoughts.
@@ -85,6 +82,10 @@ import javax.inject.Singleton | |||
) | |||
class AppVersionActivityTest { | |||
|
|||
@get:Rule | |||
val activityScenarioRule: ActivityScenarioRule<AppVersionActivity> = | |||
ActivityScenarioRule(createAppVersionActivityIntent()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We talked about this during the team meeting today @anandwana001. I suggest looking over the team notes; there were some bits in there that were recorded from the discussion I think.
@rt4914 I'm curious about one thing: does scenario rule let us handle configuration changes correctly? I was under the impression that the scenario gets recreated when the activity does (since scenarios treat DESTROYED as a terminal state). Can you confirm?
@@ -84,7 +86,7 @@ | |||
android:windowSoftInputMode="adjustResize" /> | |||
<activity | |||
android:name=".app.profile.ProfileChooserActivity" | |||
android:label="@string/profile_chooser_activity_label" | |||
android:label="@string/profile_chooser_activity_title" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to earlier PR: here & elsewhere, should these be synced to each activity's title?
@anandwana001 and @BenHenning PTAL to my reply above. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rt4914 putting espresso test result for reference.
Nit comment left
@@ -185,23 +191,17 @@ class RecentlyPlayedFragmentTest { | |||
profileId, | |||
timestampOlderThanOneWeek = true | |||
) | |||
ActivityScenario.launch<RecentlyPlayedActivity>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aren't we removing other such launches in this class?
looks like the activity launches two times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't that be wrong? I'd expect Espresso/Robolectric tests to only ever verify a single activity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should update all tests. But this was just for example for one test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @rt4914. Left some thoughts.
@@ -185,23 +191,17 @@ class RecentlyPlayedFragmentTest { | |||
profileId, | |||
timestampOlderThanOneWeek = true | |||
) | |||
ActivityScenario.launch<RecentlyPlayedActivity>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't that be wrong? I'd expect Espresso/Robolectric tests to only ever verify a single activity.
@@ -85,6 +82,10 @@ import javax.inject.Singleton | |||
) | |||
class AppVersionActivityTest { | |||
|
|||
@get:Rule | |||
val activityScenarioRule: ActivityScenarioRule<AppVersionActivity> = | |||
ActivityScenarioRule(createAppVersionActivityIntent()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep in mind we can't just copy LazyActivityScenarioRule--we would need to create our own rule that effectively does the same thing as ActivityScenarioRule but lets us customize the intent. I think the need here is pretty clear, but we need to define specifically what the desired API is. I suspect defaulting the intent is actually desirable for most situations, and having per-test overriding seems reasonable. However, it's not straightforward to implement that without accidentally opening multiple activities. I think we would need to start a draft PR introducing such a utility & iterate on the design a bit there to figure out something that would work for all cases. I do not recommend referencing the one from the blog--its existence introduces the idea that we can try to create on our own, but we need to be more careful about overly depending on external code that's not pre-packaged into a library.
Also, I'm not sure my original question regarding configuration changes was answered. See #2572 for specifics here--the perform orientation change doesn't actually force configuration changes in all environments (e.g. Robolectric). To answer this question, I think we need to check a test that passes in #2572 for both Espresso & Robolectric with the new utility, but also using ActivityScenarioRule.
Closing this as it has been filed as good-first-issue #3062 |
Fixes #2785
While adding the new test cases Ben mentioned that we are using
activityTestRule
as well asActivityScenario
for test cases. So it would be nice if somehow we can use only of such thing and keep consistency. I tried using theActivityScenarioRule
and it works correctly inAdministratorControlsActivity
andAppVersionActivity
Fixes part of #2743
This PR adds label for
AdministratorControlsActivity
andAppVersionActivity
.Along with that there are some minor changes in this PR to improve the code.
Output
a11y-label-1.mp4
Note for reviewers:
In general while working on #2743 I will need to add test cases across almost all activities in
app
module and therefore I am thinking of optimising and make more consistent test cases. Just majorly this and upcoming PRs will be focused on three things:ActivityScenarioRule
in place ofactivityTestRule
andActivityScenario
.@BenHenning and @anandwana001 WDYT about the use of
ActivityScenarioRule
usage?