【发布时间】:2013-11-07 01:48:07
【问题描述】:
我的项目是在 Android Studio 上创建的普通 Android 项目。
我google了很多来运行一个测试(在SimpleTest中测试,在这种情况下是1个测试),每个人都说我应该这样做
./gradlew -Dtest.single=SimpleTest test
在我的根文件夹中。
或者我在我的内部项目文件夹中做了
../gradlew -Dtest.single=SimpleTest test
我尝试了很多这样的方法,但它总是运行我拥有的所有测试。(所有类中的 11 个测试)
我的 build.gradle 有问题还是我缺少什么?
这是我的 build.gradle 文件。
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
classpath 'com.github.jcandksolutions.gradle:android-unit-test:1.0.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
// I changed this for this question
packageName "com.XXX.XXXX"
}
sourceSets {
instrumentTest.setRoot('src/test')
}
}
apply plugin: 'android-unit-test'
dependencies {
repositories {
mavenCentral()
}
compile 'com.android.support:support-v4:18.0.+'
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.code.gson:gson:2.2.4'
compile group:'com.squareup.picasso', name:'picasso', version:'2.1.1'
compile group:'com.squareup.okhttp', name:'okhttp', version:'1.2.1'
compile group:'com.squareup', name:'otto', version:'1.3.4'
compile group:'com.jakewharton', name:'butterknife', version:'3.0.0'
compile group:'com.github.kevinsawicki', name:'http-request', version:'5.4.1'
compile fileTree(dir: 'libs', include: '*.jar')
testCompile 'junit:junit:4.10'
testCompile 'org.robolectric:robolectric:2.2'
testCompile 'com.squareup:fest-android:1.0.+'
instrumentTestCompile 'junit:junit:4.10'
instrumentTestCompile 'org.robolectric:robolectric:2.2'
instrumentTestCompile 'com.squareup:fest-android:1.0.+'
}
tasks.withType(Compile) {
options.encoding = "UTF-8"
}
tasks.withType(Test) {
testLogging {
events 'started', 'passed'
}
}
【问题讨论】:
-
-Dtest.single是使用java插件时运行单个测试类或方法的正确方法。android-unit-test插件的情况可能有所不同。 -
@PeterNiederwieser 感谢您的评论。这是否意味着我应该为android-unit-test找到一个特定的解决方案?
-
@PeterNiederwieser 你给了我一个线索 :) 我发现
android-unit-test插件仍然不支持-Dtest.single选项,通过在Github向这个插件的开发人员询问这个选项。他为此制作了一个新补丁并将新版本上传到 Maven,所以现在我终于可以运行一个测试类了 :) 如果你回答我的问题,我会接受 :)
标签: android testing gradle android-studio robolectric