jeudi 5 février 2015

how to test the android application using Junit Test in Eclipse


for my android application i wants to write the test case . i tried with Android junit test case . but if i wants to run the android junit i want emulator or device. So i decided to go with Junit test. I have tried so far


Using this link i achieved,


But in that how can i call the UI elements like Edit text and Button Click and all



I tried so my code



@Before
public void setup() {
mActivityLogin = Robolectric.buildActivity(ActivityLogin.class).create().get();
}
@Test
public void checkActivityNotNull() throws Exception {
assertNotNull(mActivityLogin);
}


@Test
public void buttonClickShouldStartNewActivity() throws Exception
{
Button button = (Button) new ActivityLogin().findViewById(R.id.login_button);
button.performClick();
Intent intent = Robolectric.shadowOf(new ActivityLogin()).peekNextStartedActivity();
assertEquals(ActivityHome.class.getCanonicalName(), intent.getComponent().getClassName());
}

@Test
public void testButtonClick() throws Exception {
Button view = (Button) new ActivityLogin().findViewById(R.id.button1);
assertNotNull(view);
view.performClick();
assertThat(ShadowToast.getTextOfLatestToast(),equalTo("Lala"));
}


`



But if i run the Junit its says an error like : android.view.InflateException: XML file .\..\appcompat_v7\res\layout\abc_screen_toolbar.xml line #-1 (sorry, not yet implemented): Error inflating class android.support.v7.widget.Toolbar


Can any one help me to solve this problem. My simple need is i wants to test my android app without device and emulator



Aucun commentaire:

Enregistrer un commentaire