Upgrade to Pro — share decks privately, control downloads, hide ads and more …

More Effective Testing on Android Devices

More Effective Testing on Android Devices

More Effective Testing on Android Devices talk by Aurimas Liutikas at DPE Summit 2023

Aurimas Liutikas

September 01, 2023
Tweet

More Decks by Aurimas Liutikas

Other Decks in Programming

Transcript

  1. Best - JUnit tests on JVM Pros • Cacheable in

    most build systems • Multiple orders of magnitude faster • Nudges tests to unit test scope Cons • Requires refactoring to pure JVM projects / isolation from android.* APIs
  2. Best - JUnit tests on JVM Tips • Run multiple

    tests at once maxParallelForks • Gradle Enterprise test distribution
  3. Robolectric A framework for running Android tests on JVM. Built

    from Android source code with additional fakes. Google-employee maintainers, but not an Google-owned product
  4. Good - Robolectric tests Pros • Cacheable • Multiple orders

    of magnitude faster • Able to test components that have Android tie-ins • Easily fake system state (e.g. WiFi off) Cons • Not an accurate representation of a real Android device • Google support is shaky
  5. Good - Robolectric tests Tips • Cache system image downloads

    in CI • Try to minimize Android API usage • 4.10 support @GraphicsMode(NATIVE)
  6. Okay - Activity-less on device Pros • Can be <100ms

    per test method • Testing real Android behavior Cons • No caching* unless using Gradle Managed Devices (GMD) or custom runner • Sharding on through multiple connected devices • Flaky due to device instability
  7. If you must - with Activity on device Pros •

    Testing real Android behavior Cons • Really slow • No caching* unless using GMD or custom runner • Sharding on through multiple connected devices • Flaky due to device instability
  8. Robolectric tests 3 JUnit tests on JVM 4 UI tests

    1 Activity-less tests 2 Fidelity Performance
  9. Test Stability Highly Important • Flaky JVM tests are bad,

    flaky Android tests are worse • Disable/delete flaky tests as running them has high costs • State clean-up (e.g. @After) • Factory reset or Android User Profiles in custom lab
  10. Only run what you need • AOSP system images ◦

    Disable noisy applications (adb shell pm disable-user) • Automated Test Devices (ATD) images
  11. Modularize Tests Along With Features • Splitting tests allows to

    shard • Less interference between tests
  12. Key Insight on APK checksums Test results don’t change if

    both application and test APKs are the same Combined with modularization → higher hit rate
  13. Unstable APK generation • baseline.profm (issuetracker.google.com/issues/231837768) • shadow jar including

    incremental kotlin data (r.android.com/2089482) • AndroidManifest.xml android:compileSdkVersionCodename (issuetracker.google.com/issues/277836549) • r8 + API 34 record types regression
  14. Unstable APK generation • baseline.profm (issuetracker.google.com/issues/231837768) • shadow jar including

    incremental kotlin data (r.android.com/2089482) • AndroidManifest.xml android:compileSdkVersionCodename (issuetracker.google.com/issues/277836549) • r8 + API 34 record types regression
  15. Unstable APK generation • baseline.profm (issuetracker.google.com/issues/231837768) • shadow jar including

    incremental kotlin data (r.android.com/2089482) • AndroidManifest.xml android:compileSdkVersionCodename (issuetracker.google.com/issues/277836549) • r8 + API 34 record types regression
  16. Unstable APK generation • baseline.profm (issuetracker.google.com/issues/231837768) • shadow jar including

    incremental kotlin data (r.android.com/2089482) • AndroidManifest.xml android:compileSdkVersionCodename (issuetracker.google.com/issues/277836549) • r8 + API 34 record types regression
  17. Migration From Custom Lab to Firebase Test Lab Caching APK

    checksum result caching Sharding from n devices to run m APK sets → 1:1 Isolation multiple APKs sets per device →dedicated device per APK set
  18. Migration From Custom Lab to Firebase Test Lab Caching APK

    checksum result caching Sharding from n devices to run m APK sets → 1:1 Isolation multiple APKs sets per device →dedicated device per APK set
  19. Migration From Custom Lab to Firebase Test Lab Caching APK

    checksum result caching Sharding from n devices to run m APK sets → 1:1 Isolation multiple APKs sets per device →dedicated device per APK set