It’s like 10000 knives when all you need is a Spoon

Isn’t ironic that there are so many Android test automation tools and it took me half a year to stumble up on Spoon?
Spoon is an Android test automation tool that is able to run your written java tests on several devices at the same time WITHOUT rooting the device.
Spoon is developed by the company Square, the company already open sourced some really nice tools (see the Open Source Space).
Spoon uses the existing Android instrumentation and extends it to some really nice features. All you need is the application APK and the instrumentation APK, with the help of the Spoon runner both APK files will be installed via adb to all connected devices and the tests will be executed at the same time. At the end an awesome html report is generated from all connected devices.
The generated report offers a complete test execution view over all devices. You can see if the tests fails on a certain device or on all devices.
Device Test Execution overview

The device view shows every test step as screenshots (when the screenshot function is used). On this view you also have the possibility to see the test execution again! Spoon is generating an animated gif of the test steps to see what happens while test execution!

Spoon device view

To use the screenshot function simply add this to your testcode:

Spoon.screenshot(activity, "credentials_entered");

If an error occurs you can check the error and even the device log of the test device.

Spoon device log

Spoon error logFind a complete report based on the Spoon sample here. The following code snippet shows how to implement a test method.

public void testEmptyForm_ShowsBothErrors() {
    Spoon.screenshot(activity, "initial_state");

    // Make sure the initial state does not show any errors.
    assertThat(username).hasNoError();
    assertThat(password).hasNoError();

    // Click the "login" button.
    instrumentation.runOnMainSync(new Runnable() {
      @Override public void run() {
        login.performClick();
      }
    });
    instrumentation.waitForIdleSync();
}

If you know the syntax of robotium, the way Spoon is clicking a button feels different :). Why not combine both tools together?


Yes, it is possible and with that you get even better tests and reports. See the combination of Spoon and robotium:

public void testMakeASandwich_ItTastesGood() {
    Button nextButton = (Button) solo.getText("Next");

    Spoon.screenshot(activity, "initial_state");

    assertThat(nextButton).isDisabled();
    solo.clickOnText("Sandwich");
    Spoon.screenshot(activity, "selected_sandwich");
    assertThat(nextButton).isEnabled();

    solo.clickOnView(nextButton);
    Spoon.screenshot(activity, "bread");

    assertThat(nextButton).isDisabled();
    solo.clickOnText("Wheat");
    Spoon.screenshot(activity, "selected_bread");
    assertThat(nextButton).isEnabled();
}

The execution is also really simple and could be done via command line or maven:

java -jar spoon-runner-1.0.0-jar-with-dependencies.jar --apk example-app.apk --test-apk example-tests.apk

Spoon in action, the video shows the sample app execution. The sample can be found on github.

Update:
I added another video. This time spoon is used together with Robotium. In this video the Robotium sample app is used (Notepad App). The video shows 4 test devices. All devices are in standby mode. The test suite is waking up all the device and start the test execution in parallel, at the end the report is generated and looks like the sample spoon report mentioned earlier in this post.

After using the sample app, I will definitely use Spoon in one of my next Android projects. It combines so many nice features out of the box you should use it, too.

Similarities with a known song are purely coincidental.