问题
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