I saw this roboletirc example:
@Test
public void shouldHaveHappySmiles() throws Exception {
String hello = new MainActivity().getResources().getString(R.string.hello_world);
assertThat(hello, equalTo("Hello world!"));
}
@Before
public void setup() {
activity = Robolectric.buildActivity(MainActivity.class)
.create().get();
}
@Test
public void checkActivityNotNull() throws Exception {
assertNotNull(activity);
}
@Test
public void buttonClickShouldStartNewActivity() throws Exception
{
Button button = (Button) activity.findViewById(R.id.button2);
button.performClick();
Intent intent = Robolectric.shadowOf(activity).peekNextStartedActivity();
assertEquals(SecondActivity.class.getCanonicalName(), inten
t.getComponent().getClassName());
}
I tried to look in documentation but didn't understand the difference between createActivity and shadowOf. can someone please shed some light?
btw, why is there a new MainActivity().getResources().getString(R.string.hello_world); in this test? when should I use new instead of createActivity() ?
Aucun commentaire:
Enregistrer un commentaire