How to keep my test methods with proguard.cfg

早过忘川 提交于 2019-12-13 02:51:38

问题


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 static ** 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?


回答1:


The solution is

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



回答2:


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 *;
}


来源:https://stackoverflow.com/questions/6196746/how-to-keep-my-test-methods-with-proguard-cfg

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!