Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test package for different flavors in Android Studio

Tags:

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:+'

}
like image 305
user1994183 Avatar asked Mar 13 '14 09:03

user1994183


People also ask

How do I use a different Google services JSON file with multiple product flavors Android?

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.

What is Flavour dimension Android?

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 { ...

Which package do we need to use for writing Android test cases?

You will useAndroid studio to create an Android application under a package com. tutorialspoint.


2 Answers

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.

like image 133
ivagarz Avatar answered Sep 21 '22 23:09

ivagarz


This is really what did it for me: How to specify unit test folder in two-dimension flavor

dependencies {
  androidTestFlavor1Compile "..."

  //In your case androidTestStbAppleCompile         
}
like image 33
FloG Avatar answered Sep 21 '22 23:09

FloG