I started using Android Studio and gradle recently for Android development and found it much better than eclipse / ant or maven. However, I recently started trying to implement some unit tests and integration with my application. I was able to get basic tests using the Espresso scheme recently released by google. I had some tests, although I had to taunt and introduce mocking versions of objects. I used to use a dagger for another project, so I included a dagger in my project. However, now my tests will not run due to the following error:
gradle connectedCheck
...
4.1.2 failed: toolkit launch failed due to "java.lang.IllegalAccessError": EspressoApp: connectedCheck
I created a simple demo of this here: https://github.com/mwolfe38/android-espresso-dagger
Just a clone and then from the command line: gradle connectedCheck
In the above example, I tried the dependencies in several different ways, initially 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' }
but it gives me an error regarding static initialization. This is apparently caused by some static initialization code in the espresso structure relative to the dagger. So, after adding the dagger dependencies to the InstrumentTompCompile tool, I got the above IllegalAccessError.
Does anyone have luck, including a dagger in your project and espresso tests?
source share