Called from Wrong Thread Exception in Robotium Testcase

∥☆過路亽.° 提交于 2019-12-11 18:02:41

问题


I'm writing Testcase using Robotium for my android app which has multiple activities. The app implements Drawer in UI. But when solo opens drawer, it gives the exception Called From Wrong Thread Exception. Drawer loads when ActionBar Home is clicked.

public void test4Drawer()
{
    solo1.clickOnActionBarHomeButton();
    Boolean actual=solo1.searchText("About");
    Boolean expected =true;
    assertEquals("Drawer Not Loaded",expected,actual);
}

回答1:


In you setUp():

mActivity = getActivity();

And in you test case add this:

mActivity.runOnUiThread(new Runnable() {
    public void run() {
        solo1.clickOnActionBarHomeButton();
    }
});

But the error should not appear when you use standart robotium methods. If this solution does not work for you, please share full stack trace here.




回答2:


There is a problem in the 4.3 version of Robotium runOnUiThread will not help.

As the associated bug report says it's fixed in Robotium 4.3.1 version.

Download it here.

If you keep the runOnUiThread code and upgrade the lib, you will have a much more explicit exception in the logcat:

E/AndroidRuntime(32201): java.lang.RuntimeException:
  This method can not be called from the main application thread

Remove the runOnUiThread and it will be fine.



来源:https://stackoverflow.com/questions/19397713/called-from-wrong-thread-exception-in-robotium-testcase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!