7

I have 2 modules: A and B.

-A is a standalone module. Its tests run just fine all by itself.
-B is a dependent module. Its tests require a certain file in A's test folder (one test file in B extends one in A)

 

Here are what I believe to be the relevant parts of B's 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'
}

While this technically works for what I need it - it has the nasty side effect that whenever I run A's unit tests, they also run all of B's tests. I would really like if this was not the case.

 

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

Removing the sourceSets from B's build.gradle and adding (to B's dependencies) the line

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

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

 

Am I going about this the wrong way? Is there an easier/better way to include test files across modules? I'm pretty new to Gradle/Android Studio, so it's totally possible I'm missing a dead obvious solution.

Zambezi
  • 767
  • 1
  • 9
  • 19
  • Adding A's test to B's sourcesets => running A tests causes B tests to run? That doesn't make sense in my head, Is this still the case? BTW, an alternative way is to package A's tests as a jar and use that as B's testCompile dependency. – RaGe Jan 16 '16 at 20:33

1 Answers1

0

Check all your modules by tree using command:

gradle projects

It will list all your project modules and you can see if you are configuring your sub projects in a right way. Also run command:

gradle --gui

It will list all the tasks for all modules, and you can always run one module independently from other e.g.

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

OR both

gradle A:tasks B:test

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

gradle --gui

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

Testing Singh
  • 1,347
  • 1
  • 15
  • 26