Android开发者们注意了,这款测试框架一定会让你们兴奋不已,因为它是一款已基本上摆脱了模拟器测试的老套路的速率单元测试框架。Robolectric可以解压Android SDK,还能直接对应用进行测试,从而帮你轻而易举地解决所遇到的任何问题。
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!")); } } |
最新内容请见作者的GitHub页:http://qaseven.github.io/
时间: 2024-10-12 16:20:56