开发者

Android Junit test that Button has started activity

开发者 https://www.devze.com 2023-02-25 01:34 出处:网络
I have a menu with some button which each start an activity. I am writing a Junit test for this menu and I cannot seem to find out how to test that the button has loaded the correct activit开发者_开发

I have a menu with some button which each start an activity. I am writing a Junit test for this menu and I cannot seem to find out how to test that the button has loaded the correct activit开发者_开发技巧y. So far I have

public void testButtons() {
  TouchUtils.clickView(this, buttonView);
  assertEquals(com.fgap.ontrack.newsFeed.class, getActivity());
}

So far I can see that the program loads the correct activity from the emulator but it still fails the Junit test.


If you know how to use the de-bugger, you can try to see what the value of com.fgap.ontrack.newsFeed.class is and what the value of getActivity() is when it runs the test (you can use break points or look after variables to see what their value is at anytime). This might help you see if you are comparing the right things, or if you are comparing what you think you are comparing.


This is an old question but in case someone stumbles upon it.

In order to see see if an Activity has been started from a button click, you need to create an ActivityMonitor and set the activity class you are checking to see if opened.

    ActivityMonitor activityMonitor = getInstrumentation().addMonitor(activity.class.getName(), null, 

The full answer can be viewed here: https://stackoverflow.com/a/9406087/2433309

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号