Android Plugin DSL Reference 参考文档 :
UnitTestOptions ( build.gradle#android#testOptions#unitTests ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.TestOptions.UnitTestOptions.html
org.gradle.api.tasks.testing.Test 单元测试配置类 : https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html
在上一篇博客 【Android Gradle 插件】TestOptions 配置 ③ ( TestOptions#unitTests 脚本块配置 | UnitTestOptions 配置简介 ) 中 , 参考文档 https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html , 有如下单元测试配置示例 ;
Gradle 中 Test 单元测试配置类参考 :
plugins {
id 'java' // adds 'test' task
}
test {
// Discover and execute JUnit4-based tests
useJUnit()
// Discover and execute TestNG-based tests
useTestNG()
// Discover and execute JUnit Platform-based tests
useJUnitPlatform()
// set a system property for the test JVM(s)
systemProperty 'some.prop', 'value'
// explicitly include or exclude tests
include 'org/foo/**'
exclude 'org/boo/**'
// show standard out and standard error of the test JVM(s) on the console
testLogging.showStandardStreams = true
// set heap size for the test JVM(s)
minHeapSize = "128m"
maxHeapSize = "512m"
// set JVM arguments for the test JVM(s)
jvmArgs '-XX:MaxPermSize=256m'
// listen to events in the test execution lifecycle
beforeTest { descriptor ->
logger.lifecycle("Running test: " + descriptor)
}
// Fail the 'test' task on the first test failure
failFast = true
// listen to standard out and standard error of the test JVM(s)
onOutput { descriptor, event ->
logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
}
}
设置单元测试中 包含 或 排除 哪些测试 ,
// explicitly include or exclude tests
include 'org/foo/**'
exclude 'org/boo/**'
设置单元测试的 JVM 的堆大小参数 :
// set heap size for the test JVM(s)
minHeapSize = "128m"
maxHeapSize = "512m"
配置测试前执行的逻辑 :
// listen to events in the test execution lifecycle
beforeTest { descriptor ->
logger.lifecycle("Running test: " + descriptor)
}
同理 afterTest 配置的是 测试后 执行的代码逻辑 ;