我正在使用Robolectric runner测试一段代码。被测试的代码验证它没有在主线程上执行:
if (Looper.getMainLooper().getThread() == java.lang.Thread.currentThread()) {
new IllegalStateException("Method called on the UI thread");
}
Robolectric测试会引发异常,但我不想这样。
我尝试从Robolectric.getBackgroundScheduler()
运行代码,但仍然出现异常。
我的测试如何在不同的线程中开始运行?