单元测试错误与此
Called loadFromPath(/system/framework/framework-res.apk, true); mode=binary sdk=28
java.lang.Exception: Main looper has queued unexecuted runnables.
This might be the cause of the test failure. You might need a shadowOf(getMainLooper()).idle() call.
Run Code Online (Sandbox Code Playgroud)
我们正在使用 Robolectric 4.4 编译到目标 29,但确保在运行单元测试时我们的目标是 28,因为 JDK 仍然是 8 而不是 9。这是一段代码,但我似乎无法在任何地方为循环添加 idle()让这个快乐
@RunWith(AndroidJUnit4::class)
@LooperMode(LooperMode.Mode.PAUSED)
class MyRoomActivityTest {
@get:Rule
val activityRule = ActivityTestRule(MyRoomActivity::class.java, true, false)
@Inject lateinit var mockViewModel: NewMyRoomActivityViewModel
@Inject lateinit var locationManager: LocationManager
private var testViewStateLiveData: MutableLiveData<NewMyRoomActivityViewModel.MyRoomActivityViewState> = MutableLiveData()
@Before
fun setUp() {
RobolectricTestGEComponent.GraphHolder.testGraph.inject(this)
whenever(mockViewModel.viewState).thenReturn(testViewStateLiveData)
shadowOf(getMainLooper()).idle() // doesn't work here
} …Run Code Online (Sandbox Code Playgroud)