开发者

How to keep my test methods with proguard.cfg

开发者 https://www.devze.com 2023-03-10 01:58 出处:网络
For my Android instrumentation test I need a few extra entry point into my classes. Those methods are not used in the actual application. My idea was to start them all with test_ and have a general ru

For my Android instrumentation test I need a few extra entry point into my classes. Those methods are not used in the actual application. My idea was to start them all with test_ and have a general rule to exclude them from being optimized away. This is how far I got:

-keepclassmembers class com.xxx.**.* {
    public ** test_* ();
    public ** test_* (**);
    public static ** test_* ();
    public st开发者_如何学运维atic ** test_* (**);
}

But it still does not work. public static void test_destroy (final android.content.Context context) and private void dropTables (final SQLiteDatabase db) has just been removed from the code. And I have no idea why.

How is it properly used for wildcard patterns?


The solution is

-keepclassmembers class com.XXX.**.* {
    *** test_* (...);
}


Another way to do this is to use an annotation (i.e. guava's @VisibleForTesting) to mark those methods. Then in proguard you can keep all entry points and members with that annotation:

-keep @com.google.common.annotations.VisibleForTesting class *

-keepclasseswithmembers class * {
  @com.google.common.annotations.VisibleForTesting *;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消