Android的TDD:佐贺继续Robolectric和放大器;摇篮 [英] Android TDD: The saga continues with Robolectric & Gradle

查看:93
本文介绍了Android的TDD:佐贺继续Robolectric和放大器;摇篮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就在我已经取得了有效的开发和建设与 Android的Maven的插件环境,该块,摇篮,新的孩子开始做进军Android的圈子。没有热水的Groovy和与Android的摇篮插件几乎支离破碎作为操作系统本身,我击出了一些问题。特别是围绕建设图书馆项目,口味和我们的哥们的 Robolectric 的。

Just when I'd achieved an effective development and build environment with the android-maven-plugin, the new kid on the block, Gradle, starts making inroads into the Android circles. Not being hot on Groovy and with the android-gradle plugin almost as fragmented as the OS itself I've hit some issues. Specifically around building library projects, with flavours and our buddy Robolectric.

我很茫然,什么我的下一步应该是在遇到摇篮错误;

I am at a loss as to what my next move should be upon encountering the gradle error;

Cannot add a SourceSet with name 'testDebug' as a SourceSet with that name already exists.

该错误从库中有 productFlavours (即移动到0.9.2机器人构建系统)发出和摇篮 - 机器人测试-plugin 最近球队在上从Robolectric杰克的创作分叉(见的这里)。我按照调查接近耗尽所有线路,并可以报告说,米尔存在机器人试验的在我的库摇篮文件的插件发送事情出差错。

The error emanates from having productFlavours on a library (i.e. moving to the 0.9.2 android build system) and the gradle-android-test-plugin recently forked by the team over at Robolectric from Jake's creation (see here). I have followed all lines of investigation to near exhaustion and can report that the meer existence of the 'android-test' plugin within my library gradle file sends things awry.

下面是删节应用 build.gradle 与保留相关的信息文件;

Here is the abridged application build.gradle file with pertinent information retained;

apply plugin: 'android-library'
apply plugin: 'android-test'
...
android {
    compileSdkVersion 19
    buildToolsVersion '19.0.3'

    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 19
        versionCode buildNumber().toInteger()
        versionName "1.0.0"
    }

    productFlavors {
        estimote {
            dependencies {
                compile '<flavour specific dependency>'
            }
        }

        radius {
            dependencies {
                compile '<flavour specific dependency>'
            }
        }
    }
}
...
dependencies {
    compile 'com.squareup.dagger:dagger:1.2.1'
    compile 'com.squareup.dagger:dagger-compiler:1.2.1'
    compile 'com.google.code.gson:gson:2.2.+'

    // Testing dependencies
    androidTestCompile 'org.mockito:mockito-core:1.9.5'
    androidTestCompile 'com.squareup:fest-android:1.0.7'
    androidTestCompile 'org.hamcrest:hamcrest-all:1.3'
    androidTestCompile 'org.robolectric:robolectric:2.2'
    androidTestCompile 'junit:junit:4.11'
}

这里是删节根 build.gradle 文件。

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        maven {
            url 'https://oss.sonatype.org/content/repositories/snapshots'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.2'
        classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.9.+'
    }
}

allprojects {
    repositories {
        mavenLocal()
        mavenCentral()
        maven {
            url 'https://oss.sonatype.org/content/repositories/snapshots'
        }
    }
}

如果你已经走到这一步了网页,给自己的背轻拍。现在,老鹰眼睛当中,你可能已经注意到了遗漏的 sourceSets 重定向与命令类似;

If you've got this far down the page, give yourself a pat on the back. Now, the eagle eyed amongst you have probably noticed the omission on the sourceSets redirection with commands akin to;

sourceSets {
        androidTest {
            setRoot('src/test')
        }
    }

在初始误差校正这些线路将需要被复原到通知项目的结构的摇篮。该项目的结构是标准的,看起来像;

After the initial error is corrected these lines will need to be reinstated to inform gradle of the project's structure. The project's structure is standard and looks like;

- project_name
  + gradle
  - lib
     + flavour1
     + flavour2
     - main
        + java
     - test
        + java
    build.gradle
 build.gradle
 gradle.properties
 settings.gradle

什么正在被使用

该应用程序使用摇篮-1.10-所有,0.9.2 Android的摇篮插件和0.9 + 摇篮 - Android的测试插件

What is being used

The app is using gradle-1.10-all, 0.9.2 android-gradle plugin and 0.9.+ gradle-android-test-plugin.

应如何项目被设置/改变,以促进在与风味库Robolectric测试?这甚至可能吗?

How should the project be set-up/changed to facilitate Robolectric testing on a library with flavours? Is this even possible yet?

推荐答案

我碰到了同样的问题,挖成code,固定它,并提交刚刚现在被合并拉请求。请参阅公关的详细信息我的解释,但它归结为在插件code不好的优化:

I ran into the same issue, dug into the code, fixed it, and submitted a pull request which has just now been merged. See my explanation on the PR for details, but it boils down to a bad optimization in the plugin code:

https://github.com/robolectric/robolectric-gradle-plugin/拉/ 70

从今天起,你需要克隆的回购协议,并建立和安装插件本地Maven回购。下一次,他们做了发布到Maven中心(也许是释放0.13.1?),你就可以直接从那里使用该插件。

As of today you need to clone the repo and build and install the plugin to your local maven repo. The next time they do a release to maven central (perhaps release 0.13.1?), you'll be able to use the plugin directly from there.

这篇关于Android的TDD:佐贺继续Robolectric和放大器;摇篮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆