Issue
I have a multiple falvoured and multiple build type project..having some espresso and unit test cases which are running successfully but to run them successfully i have mocked my api responses currently i change my build type manually in android studio to stagging and then run those tests. Now i am integrating my project with jenkins and in jenkins my tests failed becuase jenkins is running test cases on all build types.. So long story Short I want my test cases to run only using staging build type..
Solution
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.
Answered By - Code-Apprentice
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.