4

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'

        }
    }
Community
  • 1
  • 1
Akhil Dad
  • 1,804
  • 22
  • 35
  • Hey man I have not used source set, but I was able to run flavour based test using this command pattern. (Without quotes) "./gradlew testUnitTest". – Rana Ranvijay Singh Mar 27 '17 at 05:44

2 Answers2

2

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

Rana Ranvijay Singh
  • 6,055
  • 3
  • 38
  • 54
0

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.

Prakash
  • 7,794
  • 4
  • 48
  • 44