0

I want to write a test class where i have to test on click of optionsmenu item(I have 3 items in options menu). so onclicking the options menu item I m showing the list view with the data which I am retrieving from the sd card.

the application should crash if run time exception occurs.

Kindly help me with some code snippet/example.

Here is my code but its not working.

private Solo solo;

@SuppressWarnings("deprecation")
public Mytest(
    super("com.attt.ui",Activity.class);
}

@Override
protected void setUp() throws Exception {
    super.setUp();
    solo = new Solo(getInstrumentation(), getActivity());
}

public void TestOptionsmenuItemclick() {
    solo.sendKey(Solo.MENU);
    solo.sendKey(KeyEvent.KEYCODE_MENU);
    solo.clickOnMenuItem("view");
    solo.assertCurrentActivity("hai", getName());

}

@Override
public void tearDown() throws Exception {
    solo.finishOpenedActivities();
}

     }

Help is always appreciated!

Thanks

Randroid
  • 3,688
  • 5
  • 30
  • 55
  • What do you mean by "it's not working"? Is there some exception? If so what's the call stack? – Dave C Dec 16 '13 at 17:07
  • 1
    @Dave C , its showing the error while running the application TestContentManagement] Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY – Randroid Dec 17 '13 at 05:48
  • Use real device or lanuch emulator with google api – maszter Dec 17 '13 at 16:01

4 Answers4

4

Of course it doesn't work, because it's not C# - test methods should start with "test". By the way calling:

solo.sendKey(Solo.MENU);
solo.sendKey(KeyEvent.KEYCODE_MENU);
solo.clickOnMenuItem("Review");

also doesn't make sense as clickOnMenuItem opens menu and clicks proper text.

Your test method should be like this:

public void testOptionsmenuItemclick() {
    solo.clickOnMenuItem("Review");
    solo.sleep(1000); // give it time to change activity
    solo.assertCurrentActivity("some message", SomeActivity.class);
}
maszter
  • 3,680
  • 6
  • 37
  • 53
  • 1
    You might want to edit your answer from "TestOptionsmenuItemclick" to "testOptionsmenuItemclick", i would do it but it will not let me as the edit is too small (but i think you will agree important! – Paul Harris Dec 18 '13 at 21:42
3

I solved with this:

solo.clickOnView(solo.getView(R.id.menu_item_id));
Heitor Colangelo
  • 494
  • 9
  • 16
1

You should update to latest version of robotium to fix this issue.

thienkhoi tran
  • 341
  • 2
  • 9
0

Those crazy robotium guys have added this in 5.4.4 (https://github.com/RobotiumTech/robotium/wiki/Changelog)

solo.scrollRecyclerViewToBottom(0);

Which works for me.