在寫Robolectric單元測試時,我發現調用fab.hide()
後我的getVisibility()
調用返回0(VISIBLE),所以我認爲這是由於動畫和測試,添加延遲支票。令人驚訝的是,它也已經返回VISIBLE。在實際設備上,它按預期工作並返回正確的值。檢查Android FAB的可見性總是從Robolectric測試用例返回VISIBLE
編輯:只是爲了澄清我從設計支持庫使用FAB。
我的測試代碼是非常簡單的:
fab.performClick();
ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
assertThat(fab.isShown()).isFalse();
代碼測試:
mActionBunnot.hide();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
boolean shown = mActionBunnot.isShown();
Log.d(TAG,""+shown);
}
},2000);
當通過Robolectric運行,都在這裏,在測試中,isShown
回報true
如果你評論你的處理程序,你會在測試中得到'isShown()'false嗎? –
不,它總是如此...... – vkislicins
你解決了這個問題嗎? –