我是 Android 上的新手,在测试 SplashScreen 时遇到了困难,基本上我正在做的是尝试测试启动画面是否保持 3 秒。这是 splashScreen 的代码
@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 线程并等待它。我尝试让您的调度程序获取队列并查看那里是否有任何任务。但根本没有结果。
有什么建议可以让我的测试等到新的活动被触发?
谢谢