Skip to content

Instantly share code, notes, and snippets.

Created October 26, 2013 22:25
Show Gist options
  • Save nesquena/631575e209e2cd165719 to your computer and use it in GitHub Desktop.
Save nesquena/631575e209e2cd165719 to your computer and use it in GitHub Desktop.
Android Sample Robotium Testing
package com.codepath.example.simpleapp.test;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.EditText;
import android.widget.TextView;
import com.codepath.example.simpleapp.FirstActivity;
import com.codepath.example.simpleapp.R;
import com.codepath.example.simpleapp.SecondActivity;
public class RobotiumActivityFunctionalTest extends
ActivityInstrumentationTestCase2<FirstActivity> {
// Solo Robotium helper object
private Solo solo;
public RobotiumActivityFunctionalTest() {
// Setup test case with solo
protected void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
public void testStartSecondActivity() throws Exception {
final String fieldValue = "Testing Text";
// Set a value into the text field
solo.enterText((EditText) solo.getView(, fieldValue);
// find button and click it
// or solo.clickOnView(solo.getView(;
// Wait 2 seconds for the start of the activity
solo.waitForActivity(SecondActivity.class, 2000);
solo.assertCurrentActivity("Should be second activity", SecondActivity.class);
// Search for the textView
TextView textView = (TextView) solo.getView(;
// Validate the text on the TextView
assertEquals("Text should be the field value", fieldValue,
// Finalize solo object
public void tearDown() throws Exception {
try {
} catch (Throwable e) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment