分类: Android平台
2013-07-10 20:24:19
package com.mamlambo.article.simplecalc.test;
import com.mamlambo.article.simplecalc.MainActivity;
import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.EditText;
import android.widget.TextView;
import com.mamlambo.article.simplecalc.R;
public class SimpleCalcTest extends ActivityInstrumentationTestCase2
private static Solo solo;
public SimpleCalcTest() {
super(MainActivity.class);
}
@Override
public void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
@Override
public void tearDown() throws Exception {
solo.finishOpenedActivities();
}
public void testAdd() throws Exception {
EditText value1 = (EditText)solo.getView(R.id.value1);
solo.enterText(value1, "1");
EditText value2 = (EditText)solo.getView(R.id.value2);
solo.enterText(value2, "2");
solo.clickOnButton(solo.getString(R.string.add));
TextView result = (TextView)solo.getView(R.id.result);
assertEquals("3",result.getText().toString());
solo.clearEditText(value1);
solo.clearEditText(value2);
}
public void testMulti() throws Exception {
EditText value1 = (EditText)solo.getView(R.id.value1);
solo.enterText(value1, "1");
EditText value2 = (EditText)solo.getView(R.id.value2);
solo.enterText(value2, "2");
solo.clickOnButton(solo.getString(R.string.multiply));
TextView result = (TextView)solo.getView(R.id.result);
assertEquals("2",result.getText().toString());
solo.clearEditText(value1);
solo.clearEditText(value2);
}
}