Site Loader
Auckland, New Zealand
In this post we will discuss one of the coolest and most useful testing behavior called distributed testing of application in Android. Well, many of readers like you have been asking this to me and this is the answer for your question, Spoon!!

Spoon

Android’s ever-expanding ecosystem of devices creates a unique challenge to testing applications. Spoon aims to simplify this task by distributing instrumentation test execution and displaying the results in a meaningful way. Spoon makes existing instrumentation tests more useful. Using the application APK and instrumentation APK, Spoon runs the tests on multiple devices simultaneously. Once all tests have completed, a static HTML summary is generated with detailed information about each device and test.

Spoon Components

Spoon has only two components which are basically JAR files you can download from here
  • Spoon Runner
  • Spoon Client library
Spoon client library jar file need to be added in our AUT or Test project for taking screenshots, whereas runner is responsible for running the test in multiple devices.

Spoon Command to run the test

java -jar spoon-runner-1.1.10-jar-with-dependencies.jar \
    --apk Calculator.apk --test-apk calculatortest.apk

Html Report

The HTML report generated by spoon test runner will look something like this shown below

Figure 1: Initial Spoon Report

Figure 2: Detailed Report

Figure 3: Device Log

Here is the complete video for the above discussion Here the complete code of the above video
	@SmallTest
	public void testDialog() throws Exception {
		// Declare all the controls to perform operations
		Spoon.screenshot(solo.getCurrentActivity(), "initial_state");
		EditText txtVal1 = (EditText) solo.getView(R.id.edtno1);
		EditText txtVal2 = (EditText) solo.getView(R.id.edtno2);
		RadioButton rdbtnMul = (RadioButton) solo.getView(R.id.rdMul);
		TextView viewResult = (TextView) solo.getView(R.id.txtResult);

		// Enter Text in the control
		Spoon.screenshot(solo.getCurrentActivity(), "Before_text1");
		solo.enterText(txtVal1, "12");
		Spoon.screenshot(solo.getCurrentActivity(), "Before_text2");
		solo.enterText(txtVal2, "12");

		// check for the result
		Log.d(TAG, "Checking for the results");
		if (viewResult.getText().toString().equalsIgnoreCase("24"))
			Log.d(TAG, "ADD PASSED");
		else
			Log.d(TAG, "ADD FAILED");

		// Click multiply
		Spoon.screenshot(solo.getCurrentActivity(), "Before_MultiplyRadio");
		solo.clickOnView(rdbtnMul);
		Spoon.screenshot(solo.getCurrentActivity(), "After_MultiplyRadio");

		// Verify Multipy stuffs
		if (viewResult.getText().toString().equalsIgnoreCase("144"))
			Log.d(TAG, "MUL PASSED");
		else
			Log.d(TAG, "MUL FAILED");

		Spoon.screenshot(solo.getCurrentActivity(), "final_show");
	}
Thanks for reading the post and watching the video !!! Please leave your comments and let me know if there is anything I should update in this post. Thanks, Karthik KK

Post Author: Karthik kk

One Reply to “Distributed test execution in android with Spoon”

  1. Hi,
    I am able to take screenshots of the tests using spoon with android version below 5.0 but whenever I try to run it on devices above the specified version, the app gets installed into the device but when it comes to the screenshot line it gets closed and the test passes without any log error. And this is the log error when I connect only one device of android version 4.4.2.
    [SR.runTests] Executing instrumentation suite on 1 device(s).
    Exception in thread “Thread-1” java.lang.IllegalStateException: No logcat header processed yet, failed to parse line: ——— beginning of /dev/log/system
    at com.android.ddmlib.logcat.LogCatMessageParser.processLogLines(LogCatMessageParser.java:123)
    at com.android.ddmlib.logcat.LogCatReceiverTask$LogCatOutputReceiver.processLogLines(LogCatReceiverTask.java:112)
    at com.android.ddmlib.logcat.LogCatReceiverTask$LogCatOutputReceiver.processNewLines(LogCatReceiverTask.java:107)
    at com.android.ddmlib.MultiLineReceiver.addOutput(MultiLineReceiver.java:100)
    at com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:519)
    at com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:382)
    at com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:353)
    at com.android.ddmlib.Device.executeShellCommand(Device.java:604)
    at com.android.ddmlib.logcat.LogCatReceiverTask.run(LogCatReceiverTask.java:75)
    at java.lang.Thread.run(Thread.java:745)
    2016-06-13 18:13:58 [SDR.handleFiles] Found class name dirs: []

    This is the way I take screenshot in my application.
    Spoon.screenshot(solo.getCurrentActivity(), “Before_text1”);

    Can anyone tell me if I need to give special permissions for these devices to obtain the screenshots??

    Thanks,
    Adheesh

Leave a Reply to Adheesh Cancel reply

Your email address will not be published. Required fields are marked *