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

Can someone help me understand the use of testProguardFile. Suppose I have a debug buildType and it is configured this way in the 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 rule file called test-proguard-rules.pro for testing? If I understand correctly, when I test the hardware, a separate apk is generated, but what if I do only the unit test, is that right?

what I would like to do is run β€œunit tests” (not control tests), but when using unit test apk they use the proguard rules that I defined in my project build settings.

+4
source share
2 answers

Now I see that this testProguadFile ('some proguard file') gives your test apk the proguard file that will be used for testing. This allows us to test our application using the proguard file. The apk test generated when the test is run will be confused with proguard, and then the test will run. This is a good way to test any anomalies that proguard can create in your application.

+2
source

As I try to explain on my blog - Setting up ProGuard for Android instrumental tests :

Initially, there are roughly two primary Gradle tasks for performing tool tests: assembleRelease and assembleAndroidTest . The first does what it takes to generate the .apk application. The latter starts the assembly of the toolkit for testing the toolkit .apk , which is installed on the test device with the application when performing toolkit tests (both are launched in the context of the same OS process).

Although proguardFiles sets up a list of ProGuard rule files to consider when creating an .apk application, testProguardFiles does the same for the .apk toolkit.

Thus, although the names and testProguardFiles misleading, testProguardFiles does not affect unit tests, but this is important for instrumental tests running in projects with ProGuard support.

0
source

Source: https://habr.com/ru/post/1236405/


All Articles