I'm writing unit tests in a class derived from
ActivityInstrumentationTestCase2. I know I can access anything defined
in the applications XML using findViewById(), but this application
defines its Menu programmatically. I'm trying to access that menu so I
can fire click() events to it in my tests the same way I'm doing with
Button Views etc.
To illustrate, this works fine and shows I can control/test various
Views:
public void testMyAppEdit() {
MyAppActivity main = (MyAppActivity) getActivity();
EditText val1Edit = (EditText) main.findViewById(R.id.EditText1);
val1Edit.setText("3");
Button addButton = (Button) main.findViewById(R.id.ButtonAdd);
addButton.performClick();
TextView resultText = (TextView) main.findViewById(R.id.Result);
assertEquals("Result incorrect", resultText.getText(), "3");
}
But I need to do the same to fire Menu events:
public void testMyAppAboutBox() {
MyAppActivity main = (MyAppActivity) getActivity();
// Huh? this menu has no id, and no obvious way of accessing it...
//Menu menu = (Menu) main.findViewById(id);
...
}
Thanks.
--
Android Academy http://www.androidacademy.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---