采用Android +摇篮匕首运行instrumentTests [英] Using android gradle + dagger to run instrumentTests

查看:169
本文介绍了采用Android +摇篮匕首运行instrumentTests的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始采用Android Studio和摇篮近日为Android开发,并发现它更好的整体比日食/ Ant或Maven。不过我最近开始尝试实行某种形式的单元和或集成测试,我的应用程序。我能得到使用最近谷歌发布的长者preSSO框架工作的基本测试。我有一些测试,虽然地方,我需要模拟和注入的对象嘲笑的版本。我用匕首在过去的另一个项目,所以我包括匕首刺进我的项目。因为下面的错误。但是现在我的测试将不会运行:

I have began using Android Studio and gradle recently for android development and find it much better overall than eclipse/ant or maven. However I've recently began trying to implement some kind of unit and or integration tests with my app. I was able to get basic tests working using the Espresso framework recently released by google. I had some tests though where I needed to mock and inject mocked versions of objects. I used dagger in the past for another project so I included dagger into my project. However now my tests won't run because of the following error:

gradle connectedCheck

...

4.1.2失败:仪器仪表运行失败,原因是java.lang.IllegalAccessError:ES pressoApp:connectedCheck

4.1.2 failed: Instrumentation run failed due to 'java.lang.IllegalAccessError' :EspressoApp:connectedCheck

我创建了一个简单的演示在这里: <一href="https://github.com/mwolfe38/android-es$p$psso-dagger">https://github.com/mwolfe38/android-es$p$psso-dagger

I created a simple demo of this here: https://github.com/mwolfe38/android-espresso-dagger

就在克隆,然后运行命令行:摇篮connectedCheck

Just clone and then from command line run: gradle connectedCheck

在上面我已经尝试了依赖几种不同的方式,原来是这样的:

In the above I have tried the dependencies several different ways, originally like this:

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.squareup.dagger:dagger-compiler:1.1.0'
    compile 'com.squareup.dagger:dagger:1.1.0'

    instrumentTestCompile files('libs/espresso-1.0-SNAPSHOT.jar',
            'libs/testrunner-1.0-SNAPSHOT.jar',
            'libs/testrunner-runtime-1.0-SNAPSHOT.jar')
    instrumentTestCompile 'org.hamcrest:hamcrest-all:1.3'
    instrumentTestCompile 'com.google.guava:guava:15.0'
}

不过,让我对于静态初始化错误。这似乎是由有关的匕首一些静态初始化code在ES preSSO框架造成的。所以,在添加匕首依赖于instrumentTestCompile我得到的IllegalAccessError上面提到的。

but that gives me an error regarding static initialization. This appears to be caused by some static initialization code in the espresso framework regarding dagger. So After adding dagger dependencies to instrumentTestCompile I get the IllegalAccessError mentioned above.

任何人有运气,包括匕首在你的项目中,做ES preSSO测试?

Anyone have luck including dagger in your project and doing espresso tests?

推荐答案

花了相当长一段时间,但我终于得到了它的工作。我必须做到以下几点:

Took quite awhile but I finally got it working. I had to do the following:

  1. 声明我的依赖,像这样:

  1. Declare my dependencies like so:

dependencies {
  compile 'com.android.support:appcompat-v7:+'
  compile 'com.squareup.dagger:dagger-compiler:1.1.0'
  compile 'com.squareup.dagger:dagger:1.1.0'

  instrumentTestCompile files('libs/espresso-1.0-SNAPSHOT.jar','libs/testrunner-1.0-SNAPSHOT.jar','libs/testrunner-runtime-1.0-SNAPSHOT.jar')
  instrumentTestCompile files('libs/hamcrest-core-1.1.jar', 'libs/hamcrest-library-1.1.jar', 'libs/hamcrest-integration-1.1.jar')
  instrumentTestCompile 'com.google.guava:guava:14.0.1'
}

  • 从<副本hamcrest罐子href="https://$c$c.google.com/p/android-test-kit/source/browse/#git/bin/es$p$psso-dependencies">here

    从这样的罐子中取出的许可文件(否则你会得到关于重复LICENSE.TXT文件错误)

    Remove the license files from the jars like this (or else you'll get an error about duplicate LICENSE.txt files)

    zip -d hamcrest-core-1.1.jar LICENSE.txt
    zip -d hamcrest-library-1.1.jar LICENSE.txt
    

  • 运行摇篮connectedCheck

  • Run gradle connectedCheck

    有几件事情需要注意:
    - Hamcrest 1.3没有工作对我来说,得到一个错误大约一个匹配失踪 - 疯狂多少篮球,我不得不通过跳转到这里
    。 - 祝你好运让这与Android的工作室玩好。

    A few things to note:
    - Hamcrest 1.3 didn't work for me, got an error about a matcher was missing - Crazy how many hoops I had to jump through to get here.
    - Good luck getting this to play well with android studio.

    这篇关于采用Android +摇篮匕首运行instrumentTests的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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