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

Building Android Testing Infrastructure

Mohit S
August 02, 2022

Building Android Testing Infrastructure

Mohit S

August 02, 2022
Tweet

More Decks by Mohit S

Other Decks in Programming

Transcript

  1. MODEL_ID MAKE MODEL_NAME FORM RESOLUTION OS Nexus4 LG Nexus 4

    VIRTUAL 2560 x 1600 19,21,22 sailfish Google Pixel PHYSICAL 1080 x 1920 25, 26 ~ gCloud firebase test android models list
  2. ~ gCloud firebase test android run —type instrumentation —app app-debug-unaligned.apk

    —device model=Nexus6, version=21 local=en, orientation=portrait
  3. Flank flank: 
 
 ## test shards - the amount

    of groups to split the test suite into max-test-shards: 2
  4. Flank flank: 
 
 ## test shards - the amount

    of groups to split the test suite into max-test-shards: 2 ## shard time - the amount of time tests within a shard should take shard-time: 2
  5. Recipes perfTests { devices.set([ ["model" : "Nexus5", "version" : "28"],

    ]) testTargets.set([ "class com.test.PerformanceTest" ]) }
  6. Recipes regressionTests { devices.set([ [ "model" : "Nexus4", "version" :

    "28"] ]) testTargets.set([ "class com.sample.MyRegressionTest" ]) }
  7. Problems • Tests take too long to run • Flaky

    tests • When do you run UI tests?
  8. Example - Firefox App • Open source • Nightly &

    Smoke tests • Shards with Flank
  9. Test Rails • Documentation for your test suite • View

    results over time • Collaborate with QA
  10. UI Tests Infra • Run tests in parallel • Use

    Flank with Firebase test lab • Flaky tests
  11. Structure class PresenterTest { 
 val fakeRepo = FakeRepository() 


    
 val presenter = Presenter(fakeRepo) 
 }
  12. Unit Testing Lint Rules • Enforce best practices • Coroutine

    lint test rules • Do not mock data classes
  13. Affected Module Detector App Module A Module B Module C

    assembleAndroidDebugTest connectedAndroidDebugTest testDebug
  14. Paparazzi @get:Rule val paparazzi = Paparazzi( 
 deviceConfig = PIXEL_5,

    
 theme = “android.Theme.Material.Light.NoActionBar” )
  15. Paparazzi @get:Rule val paparazzi = Paparazzi( ... ) @Test fun

    testView() { paparazzi.snapshot { UiView(uiState) } }
  16. Problem • Run only affected unit tests • Creating snapshot

    with unit testing • Unit testing database migrations
  17. Database Migrations @RenameColumn( 
 tableName = "users", 
 fromColumnName =

    "user_email", 
 toColumnName = "email" 
 ) class RenameFromUserAddressToAddress : AutoMigrationSpec
  18. Database Migrations @Database( version = 2, autoMigrations = [ AutoMigration(

    from = 1, to = 2, spec = UserDatabase.RenameFromUserAddressToAddress :: class ), ], )
  19. Test Migrations @get:Rule val helper: MigrationTestHelper = MigrationTestHelper( UserDatabase ::

    class.java, listOf( UserDatabase.RenameFromUserAddressToAddress() ), )
  20. Test Migrations @Test fun migrate1To2() { db = helper.createDatabase(TEST_DB, 1).apply

    { execSQL( """ INSERT INTO users VALUES (1, ‘User 1', ‘[email protected]') """.trimIndent() ) close() } }
  21. Test Migrations @Test fun migrate1To2() { 
 val resultCursor =

    db.query("SELECT * FROM users”) // Perform assertions }
  22. Test Migrations fun testMigration(fromVersion: Int, toVersion: Int) { migrationTestExtension.createDatabase(name, fromVersion)

    migrationTestExtension.runMigrationsAndValidate( name, toVersion, 
 *migrations 
 ) }
  23. Problem • Run only affected unit tests • Creating snapshot

    with unit testing • Unit testing database migrations
  24. Gradle Profiler Mean: 348 ms Min: 319 ms P25: 330

    ms Median: 341 ms P75: 368 ms Std dev: 22.71 ms
  25. Building Android Testing Infrastructure • Automation Tools • Building Infra

    pipelines • Snapshot Testing • Gradle Regressions