【发布时间】:2014-06-26 19:12:12
【问题描述】:
我有一个简单的 HelloWorld Android 项目(内置在 Eclipse IDE 中),我可以在 cmd 提示符下成功地为这个项目做“gradle build”。
我还为它编写了一个简单的 JUnit Android 测试项目,它在 Eclipse 中运行良好。
现在我想使用 Gradle 脚本运行这个测试项目或单元测试用例(如果我的理解有误!)。 我该怎么做?
以下是我正在使用的 build.gradle 文件。我想知道如何编写脚本代码来自动执行测试用例。
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
test {
java.srcDirs = ['src/test/java']
resources.srcDirs = ['src/test/resources']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
androidTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
【问题讨论】:
-
instrumentTest已重命名为androidTest,请参阅 github.com/Nodeclipse/nodeclipse-1/blob/master/… 的历史记录