I am experimenting flavors on an application in androidstudio. I have to write different test classes for the flavors, as I have different class files for the flavors. But I wonder if there is any option to specify test packages for each flavor in build.gradle. Here is my build.gradle for reference. I use 0.4.6 version of AndroidStudio.
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
testPackageName "com.example.tests"
}
productFlavors {
Paid {
packageName "com.example.paid"
}
Free {
packageName "com.example.free"
}
}
sourceSets {
main {
java.srcDirs = ['src/main/java']
res.srcDirs = ['src/main/res']
}
Paid {
java.srcDirs = ['src/Paid/java']
res.srcDirs = ['src/Paid/res']
}
Free {
java.srcDirs = ['src/Free/java']
res.srcDirs = ['src/Free/res']
}
}
signingConfigs {
releaseConfig {
storeFile file('filename');
storePassword('filepwd');
keyAlias "aliasname";
keyPassword "aliaspassword";
}
}
buildTypes {
release {
runProguard true
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.releaseConfig
packageNameSuffix ".release"
}
debug {
runProguard false
debuggable true
packageNameSuffix ".debug"
}
}
}
dependencies {
compile project(':androidViewPagerIndicator_library')
compile 'com.android.support:appcompat-v7:+'
}
Usage: How to use this file for different product flavors. There are only 3 steps first step is so simple just remove the google-service. json file from the root of the app/ module and save it your local system directory for the save side, & then make your product flavors like Production & Staging environment.
The flavor dimensions define the cartesian product that will be used to produce variants. Example: flavorDimensions("dimA", "dimB") productFlavors { row1 { ... dimension = "dimA" } row2 { ... dimension = "dimA" } row3 { ... dimension = "dimA" } col1 { ...
You will useAndroid studio to create an Android application under a package com. tutorialspoint.
From the documentation
Testing multi-flavors project is very similar to simpler projects.
The androidTest sourceset is used for common tests across all flavors, while each flavor can also have its own tests.
As mentioned above, sourceSets to test each flavor are created:
- android.sourceSets.androidTestFlavor1
- android.sourceSets.androidTestFlavor2
So, just as you should have now 'free' and 'paid' folders with code specific for each flavor, you can add 'androidTestFree' and 'androidTestPaid' folders where you you can add test cases specific to each one of your flavors.
This is really what did it for me: How to specify unit test folder in two-dimension flavor
dependencies {
androidTestFlavor1Compile "..."
//In your case androidTestStbAppleCompile
}
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