Skip to content

Latest commit

 

History

History
22 lines (16 loc) · 687 Bytes

test_-_robolectric.md

File metadata and controls

22 lines (16 loc) · 687 Bytes

Test - robolectric

robolectric

robolectric 提供 Android 相關的實體,例如:Activity, Context 以便離線測試。

@RunWith(RobolectricTestRunner.class)
public class MyActivityTest {

  @Test
  public void clickingButton_shouldChangeResultsViewText() throws Exception {
    MyActivity activity = Robolectric.setupActivity(MyActivity.class);

    Button button = (Button) activity.findViewById(R.id.button);
    TextView results = (TextView) activity.findViewById(R.id.results);

    button.performClick();
    assertThat(results.getText().toString()).isEqualTo("Robolectric Rocks!");
  }
}