Android-components: Migrate to androidx.test

Created on 26 Nov 2018  Â·  13Comments  Â·  Source: mozilla-mobile/android-components

After #1176 is closed we can start to migrate to use androidx.test:

Primarily this means (or could mean):

  • Replace RuntimeEnvironment.application with ApplicationProvider.getApplicationContext()
  • Switching from com.android.support.test to androidx.test
  • Get rid of RobolectricTestRunner in favor of AndroidJUnitRunner from androidx.test
  • Enable android.enableUnitTestBinaryResources=true
help wanted ✅ testing

All 13 comments

If this is still a relevant task, I can take it.

@ArazAbishov Yeah, there are still a bunch of places left where we need to migrate. Feel free to open a PR. Small PRs that only cover a subset of the repository are easier to review and get in - don't try to migrate everything at once! :)

@pocmo Sure, that makes sense :)

@pocmo service-telemetry tests are written in Java. I'm fixing deprecated dependencies in it. May I gradually convert 'em to Kotlin as well?

Upd. Or event better: convert module sources to Kotlin at first so we can use tooling (compiler warnings, detekt, ktlint etc) with it.

@dector The telemetry library is going to be replaced with glean in the future (it's already used by Fenix and Reference Browser). To be honest I wouldn't touch it at all until we can delete it. It's well tested and still used by some apps.

@pocmo Cool, got it. So it's probably make no sense to fix deprecation warnings in tests there?

yeah, let's leave it alone unless there's a strong reason that improves the quality of other modules and has a low risk for the telemetry library itself.

Little migrating instructions manual for myself:

In module's build.gradle:

  • [ ] Into android {} block add
testOptions.unitTests.includeAndroidResources = true
  • [ ] Into dependencies {} block add
testImplementation Dependencies.androidx_test_junit
  • [ ] From dependencies {} block remove
testImplementation Dependencies.testing_junit

In module's gradle.properties:

  • [ ] Create this file with content:
# TODO remove and enable globally
android.enableUnitTestBinaryResources=true

or copy it from browser-awesomebar/gradle.properties :cat: .

In test sources

  • [ ] Replace all @RunWith(RobolectricTestRunner::class) with @RunWith(AndroidJUnit4::class). Make sure that androidx.test.ext.junit.runners.AndroidJUnit4 is imported (not deprecated one).
  • [ ] _(Optionally)_ Replace all ApplicationProvider.getApplicationContext() calls with testContext (requires testImplementation project(':support-test')).

_Note_: Don't remove Dependencies.testing_robolectric from dependencies even if it's not used. For some reasons tests are failing on CI because of this (but works locally).

@dector

Regarding testOptions.unitTests.includeAndroidResources = true. I assume once we are done we can define this in the root build.gradle for all Android projects (like we setup other defaults)?

Regarding testOptions.unitTests.includeAndroidResources = true. I assume once we are done we can define this in the root build.gradle for all Android projects (like we setup other defaults)?

Yes, it definitely should be configured in allprojects {}.

@dector Can you group some of those changes into a single PR in the future? That's a lot of PRs and they all need to be merged manually and will all trigger a build for every PR and merge :)

@pocmo Sure. I was following original request. :)

Small PRs that only cover a subset of the repository are easier to review and get in

Anyway, I think only few modules left.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

csadilek picture csadilek  Â·  3Comments

pocmo picture pocmo  Â·  3Comments

mcarare picture mcarare  Â·  5Comments

pocmo picture pocmo  Â·  3Comments

boek picture boek  Â·  3Comments