TestFairy - to compile or not to compile?

written by Natalia on 2016-09-03

TestFairy is an awesome tool for testing android applications. It’s free. You can see logs and even screenshots from sessions. And there is much more but it’s not a topic for today. You can easily find those information online.

TestFairy is also easy to use. You add compile line to your app level build.gradle and then in onCreate you add one line TestFairy.begin(context, “API_KEY”); and voila - you can build your project and watch your session on TestFairy console.

The problem

After a while, when all your bugs are fixed, you would like to upload your awesome app to PlayStore. When I wanted to upload my app I wasn't sure if TestFairy should be compiled in release version. I tried to Google that but I didn’t find any answer or even similar question. Maybe this is so obvious that no one ever had any doubts.

Decision

I had doubts and I had to figure it out. Thinking it through i decided to upload my app to PlayStore without TestFairy SDK compiled in. Below I present reasons for that decision:

  • apk size - every library you compile into your project increases size of your application .apk. I believe we should always keep our .apk size as small as possible.
  • permissions - libraries, you compile can add more permissions to your app, ex. your app doesn’t need any internet permissions but TestFairy does and this permission is added to your app. The less permissions you have, the better.
  • bandwidth - TestFairy sends via Internet screenshots and data which increases bandwidth usage
  • battery - sending data via Internet has also impact on battery life

How to?

'OK! What now? Should I just remove those not needed lines of code before upload to play store?’ It would definitely work, but if You want still develop your app and test using TestFairy, you’ll need to add those lines again. The same scenario would be repeated with every single release.

Much better option would be to automate this process. It is how I did this:

First in app level debug.gradle i changed compile TestFairySDK to debugCompile TestFairySDK.

    
//app/build.gradle
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    ...
    ...
    debugCompile 'testfairy:testfairy-android-sdk:1.+@aar'
}
  

After that change if you import TestFairy in your activity it would work only for your debug builds. I think there are a few ways to solve this problem. I decided to create some kind of helper class ex.: TestFairyHelper. This class should be different for debug build types and release build types. To make it happen under src directory I created two directories called debug and release both with own TestFairyHelper class.

    
//src/debug/TestFairyHelper.java
public class TestFairyHelper {

    public static void begin(Context context) {
        TestFairy.begin(context, "MY_ID");
    }
}

//src/release/TestFairyHelper.java
public class TestFairyHelper {

    public static void begin(Context context) {
    }
}
  

As You can see both of TestFairyHelper classes have same static method but only in debug build type TestFairy is imported and called.

Now in my activity I replaced TestFairy.begin(...) with my own TestFairyHelper.begin(...).

    
//main/MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TestFairyHelper.begin(this);
}
  

And that's it.

You can find code on github.

What are your thoughts on TestFairy SDK in release version of app? Do You prefer any other solutions?