Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Unit Testing not working for Android library project

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?

like image 688
Kees van Dieren Avatar asked Feb 28 '15 13:02

Kees van Dieren


1 Answers

I found a workaround: trigger compilation manually. Gradle command that succeeds:

./gradlew clean assembleDebug assembleRelease test

Still looking for a better solution.

like image 176
Kees van Dieren Avatar answered Nov 15 '22 21:11

Kees van Dieren