我很新的Android和我寫的用Robotium一些基本的Android測試和失敗,出現異常的Android Junit測試失敗,並且「只有創建視圖層次結構的原始線程才能觸及其視圖。」
"android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views."
下面是基本的測試用例能解密: -
測試用例: -
public void testSearch() {
Activity a = getActivity();
SearchItemActivity search = new SearchItemActivity(solo);
search.searchText("ipod", a);
}
SearchItemActivity.searchText(String) is defined as
public void searchText(final String search, Activity act) {
Button v = (Button) act
.findViewById(com.test.mobile.R.id.text_search_field);
((Button) v).setText("");
((Button) v).setText(search);
solo.sendKey(Solo.ENTER);
solo.waitForActivity("FoundItemdDetailActivity");
solo.assertCurrentActivity("Expected FoundItemDetail activity","FoundItemdDetailActivity");
}
任何建議如何我可以修改我的代碼將欣賞
我想這是因爲你的測試用例試圖解僱鎖屏http://stackoverflow.com/questions/4545079/lock-the-android-device-programatically/10535284#10535284 –