grafite.pdf

 grafite.pdf

Using Gradle, Firebase Testlab for Android testing.

Adf78a43eb3d0a0354ae6c0bb1456eee?s=128

Santosh Astagi

August 15, 2018
Tweet

Transcript

  1. 5.

    Unit tests - test Running all tests - ./gradlew test

    Running all tests for a flavor - ./gradlew test{flavor}UnitTest Running individual tests - ./gradlew test{flavor}UnitTest\ —tests {packageName}.{testMethodName} Wild cards - ./gradlew test{flavor}UnitTest\ —tests *includedTestTitle*
  2. 6.

    Instrumentation tests - androidTest Running all tests - ./gradlew connectedAndroidTest

    OR cAT Running a specific test - ./gradlew connectedAndroidTest\ -Pandroid.testInstrumentationRunnerArguments.class\ ={package name}.{class name}#{method name} GOTCHA - testCoverage, orchestrator:1.0.2 with gradle plugin <3.2 android plugin - 3.3.0+, gradle version - 4.9
  3. 7.

    Filtering tests - Annotations @SmallTest - < 100ms, unit tests

    ./gradlew connectedAndroidTest\ -Pandroid.testInstrumentationRunnerArguments.size\ =Large @MediumTest - < 2s, every checkin, avoid blocking operations @LargeTest - <120s, Atleast once a day, all external communications
  4. 8.

    testOptions{} - Android Plugin DSL Reference Specify reportDir, resultsDir testBuildType

    to change default from debug unitTests {…} (Possible additions below) includeAndroidResources true returnDefaultValues true
  5. 10.

    Gradle tasks task taskname( ) { } Copy from "origin"

    into "destination" Gradle DSL method not found: 'from()' type:
  6. 11.

    Gradle tasks task taskname( ) type: //Pre built task description:

    //Meaningful enough dependsOn: //task to be executed before group: //E.g. verification, install ./gradlew taskName -PpropertyName=propertyValue project.hasProperty(“propertyName”) project.property(“propertyName”)
  7. 12.

    Unified reports task unifiedReport( type: JacocoReport, dependsOn: ['testDebugUnitTest'], ‘createDebugCoverageReport’] )

    { sourceDirectories = files(coverageSourceDirs) classDirectories = files([javaClasses], [kotlinClasses]) executionData = fileTree(dir: project.projectDir, includes: [“coverage.exec”, “testDebugUnitTest.exec”)
  8. 13.

    Unified reports task unifiedReport( type: JacocoReport, dependsOn: ['testDebugUnitTest'] ) {

    } reports { xml.enabled = true html.enabled = true } /build/reports/jacoco/…
  9. 14.
  10. 15.

    Robolectric tests coverage Prior 3.0 plugin, jacoco node in unitTests

    block Search for tasks of type test tasks.withType(Test) { jacoco.includeNoLocationClasses = true } }
  11. 19.

    app models networking ext.jacocoReport = {Project project, String variant ->

    } jacocoReport(project, ‘debug’) jacocoReport(project, ‘debug’) jacocoReport(project, ‘debug’)
  12. 20.

    Gradle methods ext.jacocoTestReport = {Project project, String variant -> }

    jacocoTestReport(project, ‘flavorName’) project.tasks.create( name: ‘jacocoTestReport’ ) { }
  13. 22.

    Unified reporting root level gradle task Update coverage directories using

    $rootProject Update class directories using $rootProject /build/reports/jacoco/…
  14. 24.

    Cloud testing Firebase testlab, Saucelabs, Genymotion, Amazon, Xamarin etc. Firebase

    testlab beta for iOS announced at I/O 18 Firebase - wide range of devices and emulators
  15. 25.

    Testlab - options, useful configurations - -timeout - max. time

    this execution can run (timeout code sent back) - - performance-metrics - CPU usage, network usage, FPS - - results-bucket - Specify gcloud bucket Specific exit codes to play nicely with scripts
  16. 26.

    Firebase console - using reports Stored in Google Cloud bucket

    Contains more than just logs, views and performance, can get code coverage, results xml, full log
  17. 29.

    Firebase console - command line Type - robo, instrumentation, game-loop

    gcloud firebase test android run --type instrumentation --app app/build/outputs/apk/debug/app-debug.apk --test app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk --devices-ids Nexus5 --os-version-ids 23 --locales en --orientations portrait --environment-variables coverage=true,coverageFile="/sdcard/coverage.ec"
  18. 31.

    Firebase - gcloud options Firebase test artifacts stores in Google

    cloud buckets Install gsutil to get CLI to interact with bucket artifacts gsutil ls gs://testingplaygroundresults
  19. 32.

    Coverage reports Enable device storage in manifest --directories-to-pull /sdcard gsutil

    cp gs://testingplaygroundresults/*/*/artifacts/ coverage.ec .
  20. 33.
  21. 35.

    Flank - Walmart Labs Scaling automated UI tests - Espresso

    and Appium Throttling support Device config Test results downloaded to project root
  22. 36.

    Flank - Walmart Labs Test 1 Test 2 Test 3

    Test 4 Test 5 Stores test times during first run Uses test times to distribute tests across devices https://github.com/TestArmada/flank