Spoon Testing with Robotium

Wolox Engineering
Wolox
Published in
3 min readJan 5, 2015

Spoon is an Android framework that aims to simplify testing on devices by distributing instrumentation test execution and displaying the results in a meaningful way. Instead of attempting to be a new form of testing, Spoon makes existing instrumentation tests more useful. If we combine it with robotium gestures for navigating the app we can build end-to-end application testing and versioning.

To get started with Spoon, you’ll need to download the jar from its webpage or get the dependency if you’re using maven or gradle.

Once you have the code you can begin writing test cases for the app with the help of Robotium. Robotium is an open-source test framework for writing automatic gray box testing cases.
This is an example of a test class using Robotium:

Notice that the tests class extends _ActivityInstrumentationTestCase2_, specifying the generic type with the Activity class that you want to test.
Next step is to define the setUp method for instantiating a Solo class, that is the Main class for development of Robotium tests.
Later you define as many test methods as you need (just remember to start the method name with the “test” prefix. In there you can navigate through the app by clicking on views, get fragments by tag or id, etc.

You can set up Spoon to run on different devices, this will allow you to test the different API levels for Android.

Spoon will also enable you to take screenshots of the current state of the application. This can be done by executing:

Spoon.screenshot(currentActivity, “tag”);

These screenshots will be stored and later displayed on a HTML file which contains the results of the tests and the screenshots.
This is an example of what the HTML file looks like:

If you are using Gradle as a dependency injection framework you can run your spoon test by executing the command:

gradlew spoon

Once they finish, you’ll get the results under the build directory of your project.

Running tests with Spoon also gives you the option of creating an APK of the current state of the app. You can also use this feature as a matter of versioning for your app if you, for example, upload it to an S3 bucket.

For further information please visit the documentation of the frameworks Robotium, Spoon.

Posted by Conrado Mader Blanco(cmaderblanco@wolox.com.ar)

www.wolox.com.ar

--

--