We have 2 product flavors in our app and one flavor has a class (FlavorSpecificClass) that the other does not. We have a junit test for FlavorSpecificClass in the src/test folder which will not compile when we are on our core variant because the class does not exist in that variant.
I cannot find a way to have separate unit tests per variant and the code will not compile in our core variant unless I comment out the references to FlavorSpecificClass. How can I get around this?
To change the build variant Android Studio uses, select Build > Select Build Variant in the menu bar. For projects without native/C++ code, the Build Variants panel has two columns: Module and Active Build Variant.
NOTE: By default, the Android Studio will generate "debug" and "release" Build Types for your project. So, to change a Build Type, all you need to do is just select your Build Type from the Build Variant and after the project sync, you are good to go.
Creating Product Flavor is pretty much easy in Android Studio, we simply need to add productFlavors block inside the Android block in the application-level build. gradle file. It's that simple to create product flavors.
Assuming you are using gradle.
So for this you need to have another directory which rests in the same place as your 'test' directory. Name the directory as 'test[BuildVariant]' and have the tests for that build variant inside that directory.
Suppose you have built variant debug, Your directory structure would look something like this, if you want to test classes that are just in debug build variant
-debug/java/...
-main/java/...
-test/java/[your tests]
-testDebug/java/[your tests for build variant debug]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With