2011年12月31日土曜日

ActivityInstrumentationTestCase2 invokeMenuActionSync

I try menu test. I used invokeMenuActionSync().
target Activity code.
This is menu create code.
menu.add(Menu.NONE, Menu.FIRST, Menu.NONE, "1");
menu.add(Menu.NONE, Menu.FIRST + 1, Menu.NONE, "2");
This is menu pushed code.
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case Menu.FIRST:
     Log.d("test", "pushed 1");
        break;
    case Menu.FIRST + 1:
     Log.d("test", "pushed 2");
        break;
    default:
        break;
    }
    return true;
}   

This is Tester.
This is push menu and push menu button.
mInstrumentation.invokeMenuActionSync(mActivity, Menu.FIRST, 0);

Do test like here.
Logcat view follow:
pushed 1

Target Activity source code is here.
Tester source code is here.

0 件のコメント:

コメントを投稿