Martin
Martin

Reputation: 11865

How to keep my test methods with proguard.cfg

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?

Upvotes: 0

Views: 1049

Answers (2)

onlythoughtworks
onlythoughtworks

Reputation: 794

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

Upvotes: 3

Martin
Martin

Reputation: 11865

The solution is

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

Upvotes: 4

Related Questions