问题描述
我玩摇篮为Android最近......它的强大,但在同一时间痛苦的。
起初,我也跟着Roboletric示例项目,试图与Robolectric测试支持基于gradle这个-Android项目。过了一会儿,我意识到Robolectric甚至不支持API 19.因此,我从我的build.gradle删除它并尝试使用JUnit和仪表测试。
我不熟悉Android或摇篮或Roboletric。我只知道,在我删除Robolectirc,每当我做了一个构建 ./ gradlew干净构建
我能够运行所有测试。但现在,我要叫 ./ gradlew connectedAndroidTest
除了运行测试,而建立
命令只要求检查
,但没有测试运行,从而始终显示成功
我在这里附上我的配置:
buildscript {
库{
mavenCentral()
}
依赖{
类路径'com.android.tools.build:gradle:0.10.+
}
}
应用插件:'机器人'库{
mavenCentral()
}安卓{
compileSdkVersion 19
buildToolsVersion '19 .1.0 defaultConfig {
9的minSdkVersion
targetSdkVersion 19
版本code 1
的versionName1.0
软件包名com。示例
testPackageNamecom.example.tests
} buildTypes {
发布 {
runProguard假
proguardFiles getDefaultProguardFile('proguard的-android.txt'),'proguard的-rules.txt
}
} productFlavors {
flavorDimensionsAppPackage,AppEnvironment appBasic {
flavorDimensionAppPackage
} {分期
flavorDimensionAppEnvironment
}
生产 {
flavorDimensionAppEnvironment
}
} sourceSets {
androidTest.setRoot('SRC /测试)
androidTestStaging.setRoot('SRC / testStaging')
androidTestProduction.setRoot('SRC / testProduction')
}}依赖{
编译文件树(导演:'库',包括:['的* .jar'])
编译com.android.support:support-v4:20.0.0
编译com.android.support:appcompat-v7:20.0.0
}
在默认情况下,当你运行构建
任务。 connectedAndroidTest
任务不运行
默认情况下,检查
任务运行,当您运行建立
任务。
所有你需要做的就是增加一个显式依赖于运行 connectedAndroidTest
任务的时候检查
任务运行
check.dependsOn connectedAndroidTest
I'm playing with Gradle for Android recently... It's powerful but painful at the same time.
Initially, I followed Roboletric sample project, trying to make a gradle-based Android project with Robolectric testing support. After a while, I realise Robolectric doesn't even support API 19. Thus, I remove it from my build.gradle and try to use Junit and Instrumentation tests.
I'm not familiar with either Android or Gradle or Roboletric. I only know that before I removed Robolectirc, whenever I made a build ./gradlew clean build
I was able to run all the tests. But now, I have to call ./gradlew connectedAndroidTest
in addition to run tests while the build
command only calls check
but no test is run and thus always show SUCCESSFUL
I have attached my configuration here:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode 1
versionName "1.0"
packageName "com.example"
testPackageName "com.example.tests"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
flavorDimensions "AppPackage", "AppEnvironment"
appBasic {
flavorDimension "AppPackage"
}
staging {
flavorDimension "AppEnvironment"
}
production {
flavorDimension "AppEnvironment"
}
}
sourceSets {
androidTest.setRoot('src/test')
androidTestStaging.setRoot('src/testStaging')
androidTestProduction.setRoot('src/testProduction')
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:20.0.0'
compile 'com.android.support:appcompat-v7:20.0.0'
}
By default the connectedAndroidTest
task don't run when you run the build
task.
By default the check
task run when you run the build
task.
All you have to do is to add an explicit dependency to run the connectedAndroidTest
task when the check
task run :
check.dependsOn connectedAndroidTest
这篇关于摇篮干净构建和connectedAndroidTest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!