我是Android新手,在測試SplashScreen時遇到困難,基本上我正在試圖測試啓動屏幕保持3秒。這是濺射屏幕Android測試Handler.postDelayed
@Override
protected void onStart() {
super.onStart();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(SplashScreenActivity.this, MainActivity.class);
startActivity(i);
finish();
}
}, SPLASH_TIME_OUT);
}
的代碼,這是我的測試方法:
@Test
public void splashScreenTimerTest() throws InterruptedException {
StopWatch timer = new StopWatch();
timer.start();
splashScreenActivityController.start();
timer.stop();
long expected = 3000L;
assertThat(String.format("The spalash screen run for longer than expected. It should stay on for [%d] but it run for [%d]",expected,timer.getTime()),timer.getTime(),equalTo(expected));
}
我使用的Android + Robolectric進行測試。
我一直在谷歌搜索了幾天,我嘗試了很多東西,但沒有結果。我嘗試獲取UI線程並等待它。我試圖讓你的調度程序來獲取隊列,看看那裏是否有任何任務。但根本沒有結果。
任何建議如何讓我的測試等到新的活動被觸發?
感謝
感謝他LP,我會再檢查! – Rabel
像魅力的偉大作品 –