16

We have a multi-module Android project, in which some modules contain UI tests and some contain Unit tests. We wish to run all UI tests from all modules using a single Gradle command and do the same thing for Unit tests.

The only way that we found to do this was with the following config inside the main app module that implements all the other sub-modules (basically make the app module know about all the other androidTest and test folders in the project):

app/build.gradle:

 sourceSets {
        androidTest.java.srcDirs += ["${project(':feature-login').projectDir}/src/androidTest/java"]
        test.java.srcDirs += ["${project(':feature-login').projectDir}/src/test/java"]
        test.java.srcDirs += ["${project(':core').projectDir}/src/test/java"]
    }

Then we run the following Gradle commands:

./gradlew app:connectedDemoDebugAndroidTest
./gradlew app:testDemoDebugUnitTest

Question: Is there a better/simpler way to achieve this? Or is there a way to add the androidTest and test folders from the above solution dynamically (using a relative path), instead of having to write the srcDirs line for each and every module (we have 40+ modules)?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Bogdan Zurac
  • 6,348
  • 11
  • 48
  • 96

2 Answers2

1

just run in terminal:

./gradlew test

Please, see docs for more options

sanya5791
  • 433
  • 4
  • 5
-1

I do that every day (I usually have a source set for unit tests and one for slower integration tests): ./gradlew check. It runs all test tasks.

From the gradle docs:

check

Depends on: test

Aggregate task that performs verification tasks, such as running the tests. Some plugins add their own verification tasks to check. You should also attach any custom Test tasks to this lifecycle task if you want them to execute for a full build. This task is added by the Base Plugin.

EricSchaefer
  • 25,272
  • 21
  • 67
  • 103