[android]android自動化測試五之Robolectric

大搜車-自娛發表於2012-02-03
官網首頁:http://pivotal.github.com/robolectric/

robolectric是android單元測試工具

下面是一個簡單的例子:


// Test class for MyActivity
@RunWith(RobolectricTestRunner.class)
public class MyActivityTest {
private Activity activity;
private Button pressMeButton;
private TextView results;

@Before
public void setUp() throws Exception {
activity = new MyActivity();
activity.onCreate(null);
pressMeButton = (Button) activity.findViewById(R.id.press_me_button);
results = (TextView) activity.findViewById(R.id.results_text_view);
}

@Test
public void shouldUpdateResultsWhenButtonIsClicked() throws Exception {
pressMeButton.performClick();
String resultsText = results.getText().toString();
assertThat(resultsText, equalTo("Testing Android Rocks!"));
}
}

相關文章