androidunit-testingandroid-gradle-pluginproguard

Android - gradle testProguardFile - what is its purpose relating to unit tests


Can someone help me understand the use of testProguardFile. Lets say i have debug buildType and its configured like this in gradle build file:

// inside android block
    debug {
        shrinkResources true  // removes unused graphics etc
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        testProguardFile('test-proguard-rules.pro')
    }

then why am i supplying another proguard rules file called test-proguard-rules.pro for testing ? If i understand correctly, when i do instrumentation testing a separate apk is generated but what if i'm doing just unit test, is it also the case ?

what i would like to be able to do is run "unit tests" (not instrumentation tests) but have the unit test apk use the proguard rules that i have defined in my project build settings.


Solution

  • Now i see what it is testProguadFile ('some proguard file') gives your test apk a proguard file to use when testing. This allows us test our app using a proguard file. The test apk generated when you run a test will be obfuscated with proguard and then the test will run. This is a good way to test for any anomalies proguard could create in your app.