TestAndroidCalculatorBlack / src / TestMain.java:
package com.hhy.androidcalculator.test;
import com.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;
@SuppressWarnings("rawtypes")
public class TestMain extends ActivityInstrumentationTestCase2 {
private Solo solo;
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.hhy.androidcalculator.MainActivity";
private static Class launcherActivityClass;
static {
try {
launcherActivityClass = Class
.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
@SuppressWarnings("unchecked")
public TestMain() throws ClassNotFoundException {
super(launcherActivityClass);
// TODO Auto-generated constructor stub
}
@Override
protected void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
public void testDisplayBlackBox() {
// Enter any integer/decimal value for first edit-field, we are writing
// 10
solo.clearEditText(0);
solo.enterText(0, "10");
// Enter any integer/decimal value for second edit-field, we are writing
// 20
solo.clearEditText(1);
solo.enterText(1, "20");
//Tap on Multiply button
solo.clickOnButton("Multiply");
//Assert that the correct resultant of 10*20 is returned
assertTrue("Problem asserting multiply", solo.searchText("200"));
}
@Override
protected void tearDown() throws Exception {
solo.finishOpenedActivities();
}
}
Manifest.xml: