简体   繁体   中英

Run unit test for main and specific flavours android

I have 5 Flavors mapped to 2 source folders with some common code written in main folder, The b folder has some extra beans for which I have written unit test, now I want to run unit test like all the unit tests in main folders run with some specific unit test written for B app.

1.Where should I place the folder specific unit test for B app. I have trued creating a folder test and placing those test in that folder and adding

unitTest { java.srcDir file('src/b/test') }

in the source set of B app but not this is not working 2.How should I place mapping for unit tests, these are not android tests, I already tired this and this but these seems to be for Android Test not for unit test.

productFlavors {
        staging {
            applicationIdSuffix = ".test"
            resValue "string", "app_name", "A Test"
            //other keys
        }
        prod {
            resValue "string", "app_name", "A"
            //other keys
        }
        dev {
            applicationIdSuffix = ".dev"
            resValue "string", "app_name", "A Dev"
            //other keys
        }

        BStaging {
            applicationIdSuffix = ".b.test"
            resValue "string", "app_name", "B Test"
         //other keys
        }

        BProd {
            applicationIdSuffix = ".b"
            resValue "string", "app_name", "B"
      //other keys
        }
    }

sourceSets {
        prod {
            java.srcDirs = ['src/a/java']
            res.srcDirs = ['src/a/res']
            resources.srcDirs = ['src/a/java']
            manifest.srcFile 'src/a/AndroidManifest.xml'
        }
        dev {
            java.srcDirs = ['src/a/java']
            res.srcDirs = ['src/a/res']
            resources.srcDirs = ['src/a/java']
            manifest.srcFile 'src/a/AndroidManifest.xml'
        }
        staging {
            java.srcDirs = ['src/a/java']
            res.srcDirs = ['src/a/res']
            resources.srcDirs = ['src/a/java']
            manifest.srcFile 'src/a/AndroidManifest.xml'
        }
        BStaging {
            java.srcDirs = ['src/b/java']
            res.srcDirs = ['src/b/res']
            resources.srcDirs = ['src/b/java']
            manifest.srcFile 'src/b/AndroidManifest.xml'
        }
        BProd {
            java.srcDirs = ['src/b/java']
            res.srcDirs = ['src/b/res']
            resources.srcDirs = ['src/b/java']
            manifest.srcFile 'src/b/AndroidManifest.xml'

        }
    }

If you have your product flavour and build type created like this.

buildTypes {
        release {
            ...
        }

        debug {
            debuggable true
        }
    }

    productFlavors {
        develop {

        }

        production {

        }
    }

You can run flavour based test using this command in your studio terminal.

  • For develop flavour and debug build : ./gradlew testDevelopDebugUnitTest
  • For develop flavour and release build : ./gradlew testDevelopReleaseUnitTest


So the pattern goes like test< Flavour >< BuildType >UnitTest

Running ./gradlew tasks will show you list of all tasks you can run for all combinations of your build types and flavors. Scroll down to find the tasks related to tests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM