Android单元测试框架:Robolectric

jopen 11年前

Robolectric 是一款Android单元测试框架,示例代码:

@RunWith(RobolectricTestRunner.class)  public class MyActivityTest {      @Test    public void clickingButton_shouldChangeResultsViewText() throws Exception {      Activity activity = Robolectric.buildActivity(MyActivity.class).create().get();        Button pressMeButton = (Button) activity.findViewById(R.id.press_me_button);      TextView results = (TextView) activity.findViewById(R.id.results_text_view);        pressMeButton.performClick();      String resultsText = results.getText().toString();      assertThat(resultsText, equalTo("Testing Android Rocks!"));    }  }

项目主页:http://www.open-open.com/lib/view/home/1379731536947