We are trying to introduce the new Android Unit Testing Support to our project.
For library project, it fails to find the src/main/java classes when running with gradlew.
Running the test from Android Studio works as expected. Running the test with gradle in an app project works as expected. Running the test with gradle in a library project fails.
I created a sample project on github, that reproduces the problem in a small project.
With gradle plugin definition apply plugin: 'com.android.application'
it works fine, with plugin definition apply plugin: 'com.android.library'
the error occurs.
The error is:
home/user/path/AndroidJvmJunitTestSpike/common/src/test/java/squins/com/common/SomeClassTest.java:11: error: cannot find symbol
assertEquals(2, new SomeClass().sum(1, 1));
^
symbol: class SomeClass
location: class SomeClassTest
/home/user/path/AndroidJvmJunitTestSpike/common/src/test/java/squins/com/common/SomeClassTest.java:16: error: cannot find symbol
new SomeClass().referenceDrawableFromR();
^
symbol: class SomeClass
location: class SomeClassTest
2 errors
:common:compileDebugUnitTestJava FAILED
Is this supposed to work? Did I miss a thing?
I found a workaround: trigger compilation manually. Gradle command that succeeds:
./gradlew clean assembleDebug assembleRelease test
Still looking for a better solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With