I am trying to share some code between my unit tests and my control tests. In my build.gradle, I implemented something like the following:
sourceSets { String sharedTestDir = 'src/sharedTest/java' test { java.srcDir sharedTestDir } androidTest { java.srcDir sharedTestDir } }
This seems like normal for regular code. However, the code generated from the annotation seems to create problems only in Android Studio. (The code works fine, but it generates red squiggles in Android Studio). Basically, Android Studio cannot find the generated classes for code that lives in src / sharedTest, even if the actual build is fine.
In case this is useful, the generated classes come from Dagger (since I split the component / module between the two types of tests). I have a custom application object that lives in sharedTest, where I notice an Android Studio error:
createApplicationComponent() { return DaggerMockApplicationComponent.create(); }
I also added the apt command for testing and androidTest:
dependencies { testApt 'com.google.dagger:dagger-compiler:2.7' androidTestApt 'com.google.dagger:dagger-compiler:2.7' }
I clearly lack something in my understanding around the source sets. Is there a cleaner way to exchange code between test and androidTest? Is there a way to get Android Studio to see this generated code? Or, in the worst case, can I make Android Studio at least ignore this error easier?
source share