public class CalculatorTest extends TestCase {
 private Calculator calculator;

 @Override
 protected void setUp() throws Exception {
  calculator = new Calculator();
 }

 public void testMultiply() {
  assertEquals(6.25f, calculator.multiply(1f, 6.25f));
 }
}

public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {
 private MainActivity mainActivity;
 private EditText editText1;
 private EditText editText2;
 private Button button;
 private TextView result;

 public MainActivityTest() {
  super("com.ssaurel.calculator", MainActivity.class);
 }

 @Override
 protected void setUp() throws Exception {
  super.setUp();
  mainActivity = getActivity();
  editText1 = (EditText) mainActivity.findViewById(com.ssaurel.calculator.R.id.EditText01);
  editText2 = (EditText) mainActivity.findViewById(com.ssaurel.calculator.R.id.EditText02);
  button = (Button) mainActivity.findViewById(com.ssaurel.calculator.R.id.Button01);
  result = (TextView) mainActivity.findViewById(com.ssaurel.calculator.R.id.TextView01);
 }

 public void testMultiply() {
  mainActivity.runOnUiThread(new Runnable() {
   @Override
   public void run() {
    editText1.setText("");
    editText1.requestFocus();
   }
  });

  getInstrumentation().waitForIdleSync();
  sendKeys(KeyEvent.KEYCODE_1);

  mainActivity.runOnUiThread(new Runnable() {
   @Override
   public void run() {
    editText2.setText("");
    editText2.requestFocus();
   }
  });

  getInstrumentation().waitForIdleSync();
  sendKeys(KeyEvent.KEYCODE_2);

  mainActivity.runOnUiThread(new Runnable() {
   @Override
   public void run() {
    button.requestFocus();
    button.performClick();
   }
  });

  getInstrumentation().waitForIdleSync();
  assertEquals("2.0", result.getText());
 }
}

<dependencies>
 <dependency>
  <groupId>junit</groupId>
  <artifactId>junit-dep</artifactId>
  <version>4.8.2</version>
  <scope>test</scope>
 </dependency>

 <dependency>
  <groupId>org.robolectric</groupId>
  <artifactId>robolectric</artifactId>
  <version>2.2</version>
  <scope>test</scope>
 </dependency>

 <dependency>
  <groupId>android</groupId>
  <artifactId>android</artifactId>
  <version>4.3_r2</version>
  <scope>provided</scope>
 </dependency>
</dependencies>

@RunWith(RobolectricTestRunner.class)
public class IntegrationTest {

 @Test
 public void testMultiply() throws Exception {
  MainActivity mainActivity = Robolectric.buildActivity(MainActivity.class).create().get();
  EditText editText1 = (EditText) mainActivity.findViewById(R.id.EditText01);
  EditText editText2 = (EditText) mainActivity.findViewById(R.id.EditText02);
  Button button = (Button) mainActivity.findViewById(R.id.Button01);
  TextView result = (TextView) mainActivity.findViewById(R.id.TextView01);
  editText1.setText("1");
  editText2.setText("2");
  button.performClick();
  Assert.assertEquals("2.0", result.getText());
 }
}

public class RobotiumTest extends ActivityInstrumentationTestCase2<MainActivity> {

 private Solo solo;

 public RobotiumTest() {
  super("com.ssaurel.calculator", MainActivity.class);
 }

 protected void setUp() throws Exception {
  super.setUp();
  solo = new Solo(getInstrumentation(), getActivity());
 }

 protected void tearDown() throws Exception {
  solo.finishOpenedActivities();
  super.tearDown();
 }

 public void testMultiply() {
  solo.assertCurrentActivity("Main Activity", MainActivity.class);
  solo.clearEditText(0);
  solo.typeText(0, "1");
  solo.clearEditText(1);
  solo.typeText(1, "2.65");
  solo.clickOnButton(solo.getString(R.string.multiplication));
  assertEquals("2.65", solo.getText(5).getText().toString());
 }
}

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

monkeyDevice = MonkeyRunner.waitForConnection()
monkeyDevice.installPackage('bin/SimpleCalculator.apk')
package = 'com.ssaurel.calculator'
activity = 'com.ssaurel.calculator.MainActivity'
runComponent = package + '/' + activity
monkeyDevice.startActivity(component=runComponent)

monkeyDevice.press("DPAD_DOWN", MonkeyDevice.DOWN_AND_UP);
monkeyDevice.press("DPAD_ENTER", MonkeyDevice.DOWN_AND_UP);
monkeyDevice.type("1");

public class UiAutomatorTest extends UiAutomatorTestCase {
 public void testDemo() throws UiObjectNotFoundException {
  getUiDevice().pressHome();
  UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
  allAppsButton.clickAndWaitForNewWindow();

  UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
  appsTab.click();

  UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
  appViews.setAsHorizontalList();

  UiObject settingsApp = appViews.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()), "SimpleCalculator");
  settingsApp.clickAndWaitForNewWindow();

  UiObject appValidation = new UiObject(new UiSelector().packageName("com.ssaurel.calculator"));
  assertTrue("Unable to detect Simple Calculator", appValidation.exists());
 }
}