I Want To Run Unit Test And Espresso Test Cases A Specific Build Type
Solution 1:
As stated in android test support flavors and build type variants?, you can create androidTest
and test
folders for specific flavors. You can also extend this to build types. Gradle allows you to build tests for any specific combination of build-type and flavor.
Let's say you have two build types (staging
and debug
) and two flavors (trial
and full
). All of the following are valid folder names:
src/androidTestStaging
- tests to run for all flavors ofstaging
buildsrc/testFull
- tests to run for all builds withfull
flavorsrc/androidTestTrialDebug
- tests to run on onlytrial
flavor ofdebug
buildsrc/testFullStaging
- tests to run on onlyfull
flavor ofstagins
build
Each of these folders have the exact same directory structure as androidTest
and test
respectively. The tests in each folder will only be run against a build which is made from all of the specified build types and flavors.
Note that this can quickly explode into a lot of combinations. For example, if you have 3 build types and 2 flavor dimensions with 3 flavors each, you now have 27 different builds. Maintaining tests for each of these can be a nightmare, so you should still follow standard software engineering practices to write tests and helper classes and functions that can be reused as much as possible.
Solution 2:
Answered by Code-apprentice on this question
If you want to run tests against a specific build type, you can specify it in the folder name: src/androidTestStaging or src/testStaging. You can combine build types and flavors to run specific tests: src/androidTestTrialStaging or src/testFullDebug.
Post a Comment for "I Want To Run Unit Test And Espresso Test Cases A Specific Build Type"