Like Unit test (junit) Android Flavor / Variant - class does not exist

We have 2 taste products in our application, and one taste has a class (FlavorSpecificClass), which the other does not. We have a junit test for FlavorSpecificClass in the src / test folder, which will not compile when we are in our main variant, because the class does not exist in this variant.

I cannot find a way to have separate unit tests for each variant, and the code will not compile in our main variant unless I comment on the links to the FlavorSpecificClass. How can I get around this?

+5
source share
1 answer

Assuming you are using gradle.

So, for this you need to have a different directory, which is in the same place as your test directory. Name the directory as 'test [BuildVariant]' and have tests for this build option inside this directory.

Suppose you built a debug option, your directory structure will look something like this if you want to test classes that are only in the debug version of the assembly

-debug/java/... -main/java/... -test/java/[your tests] -testDebug/java/[your tests for build variant debug] 
+3
source

Source: https://habr.com/ru/post/1263351/


All Articles