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.
Use the command ./gradlew test to run all tests.
Within IntelliJ IDEA, find the check task in the Gradle tool window under verification. Double click it to run. Check is also run when you run the build task, thanks to a task dependency setup by the base plugin. Gradle runs the assemble task then check.
End-to-end tests for Gradle plugins stand up a build script, apply the plugin under test and execute the build with a specific task. The outcome of the build (e.g. standard output/error or generated artifacts) verifies the correctness of the functionality.
As I try to explain in my blog post - Configuring ProGuard for Android Instrumentation Tests:
Initially, there are roughly 2 main, distinct Gradle tasks for running instrumentation tests: assembleRelease
and assembleAndroidTest
. The former executes what's needed in order to generate the app .apk
. The latter triggers the assembly of an instrumentation testing .apk
, which gets installed on the test device alongside the app when instrumentation tests are run (both are run in the context of the same OS process).
While proguardFiles
sets the list of ProGuard rule files to consider when generating the app .apk
, testProguardFiles
does the same with respect to the instrumentation .apk
.
So, while the naming is confusing, testProguardFiles
has no effect on unit tests, but it's important for instrumentation tests running in ProGuard-enabled projects.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With