Build Android with Gradle (Testing)

Config

  • testPackageName
  • testInstrumentationRunner
  • testHandleProfiling
  • testFunctionalTest
Test config example
1
2
3
4
5
6
7
8
android {
defaultConfig {
testPackageName "com.test.foo"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
testHandleProfiling true
testFunctionalTest true
}
}

Running tests

# connectedCheck flow
# Ensure the app and the test app are built (depending on assembleDebug and assembleTest)
# Install both apps
# Run the tests
# Uninstall both apps.
gradle connectedCheck

測試報告

預設會放在build/androidTest-results

Test Report config
1
2
3
4
5
6
7
8
android {
...

testOptions {
// android.testOptions.resultsDir is evaluated with Project.file(String)
resultsDir = "$project.buildDir/foo/results"
}
}

Testing Android Libraries




android {
    ...
    testBuildType "staging"
}