Skip to content
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

Fix part of #5308 : Migrate AppVersionActivityTest to ActivityScenarioRule from ActivityTestRule #5705

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

aadityaverma2011
Copy link
Contributor

@aadityaverma2011 aadityaverma2011 commented Feb 17, 2025

Explanation

Fix Part of #5308

This PR migrates the AppVersionActivityTest.kt class from using the deprecated ActivityTestRule to the recommended ActivityScenarioRule, in line with the Android Testing Library updates. The migration ensures that the test class adheres to the latest practices for testing activities in Android.

What does this PR do?: It updates AppVersionActivityTest.kt to replace ActivityTestRule with ActivityScenarioRule, improving test stability and ensuring compatibility with the current Android testing framework.
Why is this needed?: ActivityTestRule has been deprecated in favor of ActivityScenarioRule which provides better lifecycle management and more consistent behavior when working with activities in tests.
How was this tested?: After migrating the test, all tests for AppVersionActivityTest.kt were run successfully to ensure they still work as expected.
This migration is part of a broader effort to update tests across the project. Once this PR is merged, further migrations will continue for other test classes.

Essential Checklist

  • The PR title and explanation each start with "Fix Part of [BUG]: ActivityTestRule is deprecated #5308 " (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
  • Any changes to scripts/assets files have their rationale included in the PR explanation.
  • The PR follows the style guide.
  • The PR does not contain any unnecessary code changes from Android Studio (reference).
  • The PR is made from a branch that's not called "develop" and is up-to-date with "develop".
  • The PR is assigned to the appropriate reviewers (reference).

@aadityaverma2011 aadityaverma2011 marked this pull request as ready for review February 17, 2025 00:43
@aadityaverma2011 aadityaverma2011 requested a review from a team as a code owner February 17, 2025 00:43
@aadityaverma2011 aadityaverma2011 changed the title Fix part of #5308: Migrate AppVersionActivityTest to ActivityScenarioRule from ActivityTestRule Fix part of #5308 : Migrate AppVersionActivityTest to ActivityScenarioRule from ActivityTestRule Feb 17, 2025
Copy link

APK & AAB differences analysis

Note that this is a summarized snapshot. See the CI artifacts for detailed differences.

Dev

Expand to see flavor specifics

Universal APK

APK file size: 19 MiB (old), 19 MiB (new), 1752 bytes (Removed)

APK download size (estimated): 17 MiB (old), 17 MiB (new), 805 bytes (Removed)

Method count: 260329 (old), 260322 (new), 7 (Removed)

Features: 2 (old), 2 (new), 0 (No change)

Permissions: 6 (old), 6 (new), 0 (No change)

Resources: 6832 (old), 6830 (new), 2 (Removed)

  • Anim: 43 (old), 43 (new), 0 (No change)
  • Animator: 26 (old), 26 (new), 0 (No change)
  • Array: 15 (old), 15 (new), 0 (No change)
  • Attr: 922 (old), 922 (new), 0 (No change)
  • Bool: 9 (old), 9 (new), 0 (No change)
  • Color: 967 (old), 967 (new), 0 (No change)
  • Dimen: 1048 (old), 1048 (new), 0 (No change)
  • Drawable: 380 (old), 380 (new), 0 (No change)
  • Id: 1285 (old), 1285 (new), 0 (No change)
  • Integer: 37 (old), 37 (new), 0 (No change)
  • Interpolator: 11 (old), 11 (new), 0 (No change)
  • Layout: 380 (old), 380 (new), 0 (No change)
  • Menu: 3 (old), 3 (new), 0 (No change)
  • Mipmap: 1 (old), 1 (new), 0 (No change)
  • Plurals: 10 (old), 10 (new), 0 (No change)
  • Raw: 2 (old), 2 (new), 0 (No change)
  • String: 855 (old), 853 (new), 2 (Removed):
    • string/selected_image_region_selection_content_description (removed)
    • string/unselected_image_region_selection_content_description (removed)
  • Style: 832 (old), 832 (new), 0 (No change)
  • Xml: 6 (old), 6 (new), 0 (No change)

Lesson assets: 111 (old), 111 (new), 0 (No change)

AAB differences

Expand to see AAB specifics

Supported configurations:

  • hdpi (same)
  • ldpi (same)
  • mdpi (same)
  • tvdpi (same)
  • xhdpi (same)
  • xxhdpi (same)
  • xxxhdpi (same)

Base APK

APK file size: 18 MiB (old), 18 MiB (new), 1752 bytes (Removed)
APK download size (estimated): 17 MiB (old), 17 MiB (new), 741 bytes (Removed)
Method count: 260329 (old), 260322 (new), 7 (Removed)
Resources: 6782 (old), 6780 (new), 2 (Removed)

  • String: 855 (old), 853 (new), 2 (Removed)

Configuration hdpi

APK file size: 50 KiB (old), 50 KiB (new), 0 bytes (No change)
APK download size (estimated): 18 KiB (old), 18 KiB (new), 0 bytes (No change)

Configuration ldpi

APK file size: 49 KiB (old), 49 KiB (new), 0 bytes (No change)
APK download size (estimated): 14 KiB (old), 14 KiB (new), 0 bytes (No change)

Configuration mdpi

APK file size: 45 KiB (old), 45 KiB (new), 0 bytes (No change)
APK download size (estimated): 14 KiB (old), 14 KiB (new), 0 bytes (No change)

Configuration tvdpi

APK file size: 86 KiB (old), 86 KiB (new), 0 bytes (No change)
APK download size (estimated): 29 KiB (old), 29 KiB (new), 0 bytes (No change)

Configuration xhdpi

APK file size: 57 KiB (old), 57 KiB (new), 0 bytes (No change)
APK download size (estimated): 21 KiB (old), 21 KiB (new), 0 bytes (No change)

Configuration xxhdpi

APK file size: 63 KiB (old), 63 KiB (new), 0 bytes (No change)
APK download size (estimated): 29 KiB (old), 29 KiB (new), 0 bytes (No change)

Configuration xxxhdpi

APK file size: 63 KiB (old), 63 KiB (new), 0 bytes (No change)
APK download size (estimated): 28 KiB (old), 28 KiB (new), 0 bytes (No change)

Alpha

Expand to see flavor specifics

Universal APK

APK file size: 11 MiB (old), 11 MiB (new), 1536 bytes (Removed)

APK download size (estimated): 10 MiB (old), 10 MiB (new), 3910 bytes (Removed)

Method count: 115836 (old), 115840 (new), 4 (Added)

Features: 2 (old), 2 (new), 0 (No change)

Permissions: 6 (old), 6 (new), 0 (No change)

Resources: 5800 (old), 5798 (new), 2 (Removed)

  • Anim: 33 (old), 33 (new), 0 (No change)
  • Animator: 24 (old), 24 (new), 0 (No change)
  • Array: 14 (old), 14 (new), 0 (No change)
  • Attr: 888 (old), 888 (new), 0 (No change)
  • Bool: 8 (old), 8 (new), 0 (No change)
  • Color: 820 (old), 820 (new), 0 (No change)
  • Dimen: 780 (old), 780 (new), 0 (No change)
  • Drawable: 342 (old), 342 (new), 0 (No change)
  • Id: 1231 (old), 1231 (new), 0 (No change)
  • Integer: 32 (old), 32 (new), 0 (No change)
  • Interpolator: 11 (old), 11 (new), 0 (No change)
  • Layout: 343 (old), 343 (new), 0 (No change)
  • Menu: 1 (old), 1 (new), 0 (No change)
  • Mipmap: 1 (old), 1 (new), 0 (No change)
  • Plurals: 10 (old), 10 (new), 0 (No change)
  • String: 788 (old), 786 (new), 2 (Removed):
    • string/selected_image_region_selection_content_description (removed)
    • string/unselected_image_region_selection_content_description (removed)
  • Style: 473 (old), 473 (new), 0 (No change)
  • Xml: 1 (old), 1 (new), 0 (No change)

Lesson assets: 111 (old), 111 (new), 0 (No change)

AAB differences

Expand to see AAB specifics

Supported configurations:

  • hdpi (same)
  • ldpi (same)
  • mdpi (same)
  • tvdpi (same)
  • xhdpi (same)
  • xxhdpi (same)
  • xxxhdpi (same)

Base APK

APK file size: 11 MiB (old), 11 MiB (new), 1548 bytes (Removed)
APK download size (estimated): 10 MiB (old), 10 MiB (new), 715 bytes (Removed)
Method count: 115836 (old), 115840 (new), 4 (Added)
Resources: 5757 (old), 5755 (new), 2 (Removed)

  • String: 788 (old), 786 (new), 2 (Removed)

Configuration hdpi

APK file size: 43 KiB (old), 43 KiB (new), 0 bytes (No change)
APK download size (estimated): 17 KiB (old), 17 KiB (new), 0 bytes (No change)

Configuration ldpi

APK file size: 44 KiB (old), 44 KiB (new), 0 bytes (No change)
APK download size (estimated): 13 KiB (old), 13 KiB (new), 0 bytes (No change)

Configuration mdpi

APK file size: 38 KiB (old), 38 KiB (new), 0 bytes (No change)
APK download size (estimated): 13 KiB (old), 13 KiB (new), 0 bytes (No change)

Configuration tvdpi

APK file size: 73 KiB (old), 73 KiB (new), 0 bytes (No change)
APK download size (estimated): 27 KiB (old), 27 KiB (new), 0 bytes (No change)

Configuration xhdpi

APK file size: 50 KiB (old), 50 KiB (new), 0 bytes (No change)
APK download size (estimated): 20 KiB (old), 20 KiB (new), 0 bytes (No change)

Configuration xxhdpi

APK file size: 55 KiB (old), 55 KiB (new), 0 bytes (No change)
APK download size (estimated): 28 KiB (old), 28 KiB (new), 0 bytes (No change)

Configuration xxxhdpi

APK file size: 55 KiB (old), 55 KiB (new), 0 bytes (No change)
APK download size (estimated): 27 KiB (old), 27 KiB (new), 0 bytes (No change)

Beta

Expand to see flavor specifics

Universal APK

APK file size: 11 MiB (old), 11 MiB (new), 1528 bytes (Removed)

APK download size (estimated): 10 MiB (old), 10 MiB (new), 1577 bytes (Removed)

Method count: 115842 (old), 115846 (new), 4 (Added)

Features: 2 (old), 2 (new), 0 (No change)

Permissions: 6 (old), 6 (new), 0 (No change)

Resources: 5800 (old), 5798 (new), 2 (Removed)

  • Anim: 33 (old), 33 (new), 0 (No change)
  • Animator: 24 (old), 24 (new), 0 (No change)
  • Array: 14 (old), 14 (new), 0 (No change)
  • Attr: 888 (old), 888 (new), 0 (No change)
  • Bool: 8 (old), 8 (new), 0 (No change)
  • Color: 820 (old), 820 (new), 0 (No change)
  • Dimen: 780 (old), 780 (new), 0 (No change)
  • Drawable: 342 (old), 342 (new), 0 (No change)
  • Id: 1231 (old), 1231 (new), 0 (No change)
  • Integer: 32 (old), 32 (new), 0 (No change)
  • Interpolator: 11 (old), 11 (new), 0 (No change)
  • Layout: 343 (old), 343 (new), 0 (No change)
  • Menu: 1 (old), 1 (new), 0 (No change)
  • Mipmap: 1 (old), 1 (new), 0 (No change)
  • Plurals: 10 (old), 10 (new), 0 (No change)
  • String: 788 (old), 786 (new), 2 (Removed):
    • string/selected_image_region_selection_content_description (removed)
    • string/unselected_image_region_selection_content_description (removed)
  • Style: 473 (old), 473 (new), 0 (No change)
  • Xml: 1 (old), 1 (new), 0 (No change)

Lesson assets: 111 (old), 111 (new), 0 (No change)

AAB differences

Expand to see AAB specifics

Supported configurations:

  • hdpi (same)
  • ldpi (same)
  • mdpi (same)
  • tvdpi (same)
  • xhdpi (same)
  • xxhdpi (same)
  • xxxhdpi (same)

Base APK

APK file size: 10 MiB (old), 10 MiB (new), 1536 bytes (Removed)
APK download size (estimated): 9 MiB (old), 9 MiB (new), 1144 bytes (Removed)
Method count: 115842 (old), 115846 (new), 4 (Added)
Resources: 5757 (old), 5755 (new), 2 (Removed)

  • String: 788 (old), 786 (new), 2 (Removed)

Configuration hdpi

APK file size: 43 KiB (old), 43 KiB (new), 0 bytes (No change)
APK download size (estimated): 17 KiB (old), 17 KiB (new), 0 bytes (No change)

Configuration ldpi

APK file size: 44 KiB (old), 44 KiB (new), 0 bytes (No change)
APK download size (estimated): 13 KiB (old), 13 KiB (new), 0 bytes (No change)

Configuration mdpi

APK file size: 38 KiB (old), 38 KiB (new), 0 bytes (No change)
APK download size (estimated): 13 KiB (old), 13 KiB (new), 0 bytes (No change)

Configuration tvdpi

APK file size: 73 KiB (old), 73 KiB (new), 0 bytes (No change)
APK download size (estimated): 27 KiB (old), 27 KiB (new), 0 bytes (No change)

Configuration xhdpi

APK file size: 50 KiB (old), 50 KiB (new), 0 bytes (No change)
APK download size (estimated): 20 KiB (old), 20 KiB (new), 0 bytes (No change)

Configuration xxhdpi

APK file size: 55 KiB (old), 55 KiB (new), 0 bytes (No change)
APK download size (estimated): 28 KiB (old), 28 KiB (new), 0 bytes (No change)

Configuration xxxhdpi

APK file size: 55 KiB (old), 55 KiB (new), 0 bytes (No change)
APK download size (estimated): 27 KiB (old), 27 KiB (new), 0 bytes (No change)

Ga

Expand to see flavor specifics

Universal APK

APK file size: 11 MiB (old), 11 MiB (new), 1500 bytes (Removed)

APK download size (estimated): 10 MiB (old), 10 MiB (new), 240 bytes (Removed)

Method count: 115842 (old), 115846 (new), 4 (Added)

Features: 2 (old), 2 (new), 0 (No change)

Permissions: 6 (old), 6 (new), 0 (No change)

Resources: 5800 (old), 5798 (new), 2 (Removed)

  • Anim: 33 (old), 33 (new), 0 (No change)
  • Animator: 24 (old), 24 (new), 0 (No change)
  • Array: 14 (old), 14 (new), 0 (No change)
  • Attr: 888 (old), 888 (new), 0 (No change)
  • Bool: 8 (old), 8 (new), 0 (No change)
  • Color: 820 (old), 820 (new), 0 (No change)
  • Dimen: 780 (old), 780 (new), 0 (No change)
  • Drawable: 342 (old), 342 (new), 0 (No change)
  • Id: 1231 (old), 1231 (new), 0 (No change)
  • Integer: 32 (old), 32 (new), 0 (No change)
  • Interpolator: 11 (old), 11 (new), 0 (No change)
  • Layout: 343 (old), 343 (new), 0 (No change)
  • Menu: 1 (old), 1 (new), 0 (No change)
  • Mipmap: 1 (old), 1 (new), 0 (No change)
  • Plurals: 10 (old), 10 (new), 0 (No change)
  • String: 788 (old), 786 (new), 2 (Removed):
    • string/selected_image_region_selection_content_description (removed)
    • string/unselected_image_region_selection_content_description (removed)
  • Style: 473 (old), 473 (new), 0 (No change)
  • Xml: 1 (old), 1 (new), 0 (No change)

Lesson assets: 111 (old), 111 (new), 0 (No change)

AAB differences

Expand to see AAB specifics

Supported configurations:

  • hdpi (same)
  • ldpi (same)
  • mdpi (same)
  • tvdpi (same)
  • xhdpi (same)
  • xxhdpi (same)
  • xxxhdpi (same)

Base APK

APK file size: 10 MiB (old), 10 MiB (new), 1508 bytes (Removed)
APK download size (estimated): 9 MiB (old), 9 MiB (new), 192 bytes (Removed)
Method count: 115842 (old), 115846 (new), 4 (Added)
Resources: 5757 (old), 5755 (new), 2 (Removed)

  • String: 788 (old), 786 (new), 2 (Removed)

Configuration hdpi

APK file size: 43 KiB (old), 43 KiB (new), 0 bytes (No change)
APK download size (estimated): 17 KiB (old), 17 KiB (new), 0 bytes (No change)

Configuration ldpi

APK file size: 44 KiB (old), 44 KiB (new), 0 bytes (No change)
APK download size (estimated): 13 KiB (old), 13 KiB (new), 0 bytes (No change)

Configuration mdpi

APK file size: 38 KiB (old), 38 KiB (new), 0 bytes (No change)
APK download size (estimated): 13 KiB (old), 13 KiB (new), 0 bytes (No change)

Configuration tvdpi

APK file size: 73 KiB (old), 73 KiB (new), 0 bytes (No change)
APK download size (estimated): 27 KiB (old), 27 KiB (new), 0 bytes (No change)

Configuration xhdpi

APK file size: 50 KiB (old), 50 KiB (new), 0 bytes (No change)
APK download size (estimated): 20 KiB (old), 20 KiB (new), 0 bytes (No change)

Configuration xxhdpi

APK file size: 55 KiB (old), 55 KiB (new), 0 bytes (No change)
APK download size (estimated): 28 KiB (old), 28 KiB (new), 0 bytes (No change)

Configuration xxxhdpi

APK file size: 55 KiB (old), 55 KiB (new), 0 bytes (No change)
APK download size (estimated): 27 KiB (old), 27 KiB (new), 0 bytes (No change)

@adhiamboperes adhiamboperes self-assigned this Feb 18, 2025
Copy link
Collaborator

@adhiamboperes adhiamboperes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @aadityaverma2011!

I have left several comments, but I would like to highlight that we typically avoid introducing new patterns in the codebase unless there is a strong foundation and explanation for it. Otherwise, we prefer using already established patterns, and you can check other existing files for reference on how accomplish certain tasks, especially repetitive ones.

@@ -17,6 +17,7 @@ import javax.inject.Singleton
* This class should never be used directly. Instead of accessing the locale directly, use
* [AppLanguageResourceHandler].
*/

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no spacing after a KDoc.

Comment on lines +80 to +94
fun resetLocale() {
if (!isInitialized()) {
// Initialize with system default locale if not already set
initializeLocale(
localeController.reconstituteDisplayLocale(
localeController.getLikelyDefaultAppStringLocaleContext()
)
)
} else {
// If already initialized, just update the locale
displayLocale = localeController.reconstituteDisplayLocale(
localeController.getLikelyDefaultAppStringLocaleContext()
)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are unrelated to this PR. if fixing a different issue, please also include that issue number in the PR title and descriprion. If fixing an unfile issue, Please create that issue so that we can review the details.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain why this new module is required? I do not think it is. You could just inject LocaleController, or any controller in a class where you want to use it.

@@ -115,23 +118,23 @@ import javax.inject.Singleton
qualifiers = "port-xxhdpi"
)
class AppVersionActivityTest {
@get:Rule
@get:Rule(order = 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to specify rule order.

Comment on lines +127 to +128
@get:Rule(order = 2)
val activityScenarioRule = ActivityScenarioRule(AppVersionActivity::class.java)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could get rid of this rule completely, and instead use ActivityScenario.launch to initialize acticities in tests. Please look at this class(OnboardingFragmentTest) for examples of how to implement this.

Comment on lines +164 to +166
// Reset locale after each test
if (::appLanguageLocaleHandler.isInitialized) {
appLanguageLocaleHandler.resetLocale()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

testCoroutineDispatchers.runCurrent()

// Scroll to the item in the RecyclerView
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments are not required since ViewActions and Matchers are pretty self explanatory. We only add comments whne it is not clear some code has been added.

Comment on lines +281 to +289
fun getCurrentActivity(): Activity? {
val activity = arrayOfNulls<Activity>(1)
InstrumentationRegistry.getInstrumentation().runOnMainSync {
activity[0] = ActivityLifecycleMonitorRegistry.getInstance()
.getActivitiesInStage(Stage.RESUMED)
.firstOrNull()
}
return activity[0]
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently don't use this implementation in any of our UI tests, and there is probaby an existing pattern that you can follow to achieve the same objective as here. Please search for any tests that use ActivityScenario.launch to see the implementation patterns used.

Comment on lines +302 to +307
// private fun launchAppVersionActivityIntent(): ActivityScenario<AppVersionActivity> {
// val intent = AppVersionActivity.createAppVersionActivityIntent(
// ApplicationProvider.getApplicationContext()
// )
// return ActivityScenario.launch(intent)
// }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When submitting a PR, be sure to delete any commented out code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants