Test package for different flavors in Android Studio

南楼画角 提交于 2019-12-21 03:33:21

问题


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

}

回答1:


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.




回答2:


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

dependencies {
  androidTestFlavor1Compile "..."

  //In your case androidTestStbAppleCompile         
}


来源:https://stackoverflow.com/questions/22373655/test-package-for-different-flavors-in-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!