简体   繁体   中英

Run all UI/Unit tests from a multi-module project using a single command

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)?

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)?

just run in terminal:

./gradlew test

Please, see docs for more options

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM