Test Component accessible from src/test/java and src/androidTest/java

97 views
Skip to first unread message

James S

unread,
Nov 23, 2015, 9:42:40 PM11/23/15
to Dagger Discuss
Hi guys,

I have have an app that uses Dagger 2.0.1, Robolectric 3.0, Espresso 2.2.1.

My app has both src/test/ folder (for Robolectric and unit tests) and src/androidTest (for Espresso and unit tests). There are 2 build types in Gradle: release (no test code included) and debug (includes test code). Currently I have a single Dagger AppComponent in /src/main/java

question 1: What is the best practice about adding a TestAppComponent? Would I place it under  src/androidTest or  src/test? What I like to do is to be able to access it from both types of tests.

question 2: I cannot seem to generate a Dagger code for TestAppComponent when I place my component code annotated with @Component under either src/androidTest or  src/test.  What gradle task would I run to generate Dagger code?

Thanks for any help! 
 

Dorian Cussen

unread,
Nov 27, 2015, 7:28:19 AM11/27/15
to Dagger Discuss
Q1 - AFAIK android studio 2.0 allows you to share code between both types of test project

Jake Wharton

unread,
Nov 27, 2015, 10:27:30 AM11/27/15
to dagger-...@googlegroups.com
It allows both source sets to be active for refactoring purposes. You have always been able to share code between the two by adding a folder to both source sets. Example: http://blog.danlew.net/2015/11/02/sharing-code-between-unit-tests-and-instrumentation-tests-on-android/

On Fri, Nov 27, 2015 at 7:28 AM Dorian Cussen <do...@kodroid.com> wrote:
Q1 - AFAIK android studio 2.0 allows you to share code between both types of test project

--
You received this message because you are subscribed to the Google Groups "Dagger Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dagger-discus...@googlegroups.com.
To post to this group, send email to dagger-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dorian Cussen

unread,
Nov 27, 2015, 10:29:25 AM11/27/15
to dagger-...@googlegroups.com
Yup! You are right of course!


----


Dorian Cussen | Android Developer | kodroid


--
You received this message because you are subscribed to a topic in the Google Groups "Dagger Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dagger-discuss/xvy_CMwRIiA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dagger-discus...@googlegroups.com.

Ron Shapiro

unread,
Nov 27, 2015, 11:01:01 AM11/27/15
to dagger-...@googlegroups.com

Regarding your second question, you probably need to have the Dagger compiler run in the androidTest or test scope. I imagine the apt gradle plugin has an androidTestApt or testApt accordingly

Reply all
Reply to author
Forward
0 new messages