Slide 1

Slide 1 text

Gra-Fi-Te Leveraging Gradle and Firebase for Android Testing Santosh Astagi Rally Health

Slide 2

Slide 2 text

Gradlew wrapper - ./gradlew

Slide 3

Slide 3 text

Gradle tasks - ./gradlew tasks

Slide 4

Slide 4 text

Android plugin for gradle - com.android.tools.build:gradle:#.#.# Android tasks Build tasks Install tasks Verification tasks - Testing tasks

Slide 5

Slide 5 text

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*

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

testOptions{} - Android Plugin DSL Reference Specify reportDir, resultsDir testBuildType to change default from debug unitTests {…} (Possible additions below) includeAndroidResources true returnDefaultValues true

Slide 9

Slide 9 text

Coverage reports testCoverageEnabled true ./gradlew createDebugCoverageReport apply plugin: "jacoco" Coverage report: jacoco/test{flavor}UnitTest.exec

Slide 10

Slide 10 text

Gradle tasks task taskname( ) { } Copy from "origin" into "destination" Gradle DSL method not found: 'from()' type:

Slide 11

Slide 11 text

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”)

Slide 12

Slide 12 text

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”)

Slide 13

Slide 13 text

Unified reports task unifiedReport( type: JacocoReport, dependsOn: ['testDebugUnitTest'] ) { } reports { xml.enabled = true html.enabled = true } /build/reports/jacoco/…

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Robolectric tests coverage Prior 3.0 plugin, jacoco node in unitTests block Search for tasks of type test tasks.withType(Test) { jacoco.includeNoLocationClasses = true } }

Slide 16

Slide 16 text

Kotlin data classes

Slide 17

Slide 17 text

Jacoco snapshot build https://oss.sonatype.org/content/repositories/snapshots project.jacoco { toolVersion = '0.8.2-SNAPSHOT' }

Slide 18

Slide 18 text

Multi module apps

Slide 19

Slide 19 text

app models networking ext.jacocoReport = {Project project, String variant -> } jacocoReport(project, ‘debug’) jacocoReport(project, ‘debug’) jacocoReport(project, ‘debug’)

Slide 20

Slide 20 text

Gradle methods ext.jacocoTestReport = {Project project, String variant -> } jacocoTestReport(project, ‘flavorName’) project.tasks.create( name: ‘jacocoTestReport’ ) { }

Slide 21

Slide 21 text

Combining reports apply plugin: ‘android-reporting’ ./gradlew connectedAndroidTest mergeAndroidReports {root project}/build/reports ./gradlew createDebugCoverageReport mergeAndroidReports

Slide 22

Slide 22 text

Unified reporting root level gradle task Update coverage directories using $rootProject Update class directories using $rootProject /build/reports/jacoco/…

Slide 23

Slide 23 text

Cloud testing

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

Firebase testlab - Running tests

Slide 28

Slide 28 text

Firebase - device options gcloud firebase test android models list

Slide 29

Slide 29 text

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"

Slide 30

Slide 30 text

Firebase testlab - Artifacts and fetching

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

Coverage reports Enable device storage in manifest --directories-to-pull /sdcard gsutil cp gs://testingplaygroundresults/*/*/artifacts/ coverage.ec .

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

Test sharing through flank

Slide 35

Slide 35 text

Flank - Walmart Labs Scaling automated UI tests - Espresso and Appium Throttling support Device config Test results downloaded to project root

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

https://github.com/sastagi/grafite @sastagi Thank you