Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 968
Vlad Kuts Avatar asked Feb 21 '15 07:02

Vlad Kuts


1 Answers

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.

like image 99
njzk2 Avatar answered Sep 28 '22 22:09

njzk2