Android Gradle 1.1 - adding test dependency on other project tests

I have 2 modules: A and B.

-A is a standalone module. His tests just work just fine. -B is the dependent module. His tests require a specific file in the test folder (one test file in B extends one of A)

Here is what I consider relevant parts of B build.gradle :

 android { ... sourceSets { test.java.srcDirs += "../A/src/test/java" } } dependencies { compile project(':A') testCompile 'junit:junit:4.10' testCompile 'org.robolectric:robolectric:2.4' testCompile 'org.mockito:mockito-core:1.9.5' } 

Although this technically works for what I need, it has an unpleasant side effect: whenever I run unit tests, they also run all of the B tests. I would really like it if it werenโ€™t.

I am using Android Gradle 1.1 (along with Android Studio 1.1), and I think this is causing me some problems. I tried all the solutions I could find - unfortunately, none of them seem to work for Android Gradle 1.1 - for example:

Removing sourceSets from B build.gradle and adding (to B dependencies) a string

  testCompile project(':A').sourceSets.test.output 

Could not find property 'test' on SourceSet container. build error. Could not find property 'test' on SourceSet container.

Am I really wrong? Is there an easier / better way to include test files through modules? I am new to Gradle / Android Studio, so it is possible that I am missing a dead, obvious solution.

+7
android android-studio android-gradle gradle
source share
1 answer

Test all your modules on the tree with the command:

 gradle projects 

It will display all of your project modules, and you can see if you are setting up your subprojects correctly. Also run the command:

 gradle --gui 

It will list all tasks for all modules, and you can always run one module independently of others, for example.

 gradle A:tasks gradle A:test gradle B:test 

OR both

 gradle A:tasks B:test 

Note. You do not need to specify A if it is the root project and submodules B, C, D, but for the submodules you need to specify. When you do:

 gradle --gui 

You can double-click any task to see how it works, and you can do the same manually from the command line. Hope this helps

0
source share

All Articles