简体   繁体   中英

No Dagger2 generated files for JUnit tests

A new AndroidStudio 1.1 version introduced the unit testing support. This URL http://tools.android.com/tech-docs/unit-testing-support provides step-by-step instruction how to setup IDE to run JUnit tests for Android sources.

This plugin https://bitbucket.org/hvisser/android-apt used to provide Dagger2 generated files to AS and it works OK for usual Android code but unfortunately there is no generated Dagger2 files for any JUnit test class. I tried to configure dependency like

androidTestApt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'

according to android-apt plugin documentation but without success.

I think the problem is in different sources directory for Unit tests - it's src/test/java instead of src/androidTest/java that used by android instrumentation tests.

Can you please provide any help or info how to resolve this trouble?

Having

// You version may vary
androidTestApt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT' 

in your dependencies, open a terminal in your project, run

./gradlew assembleTest

This will generate the Dagger component classes living under your androidTest source set.

Go back to Android Studio, the class now exists and can be used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM