bouzuya.hatenablog.com

ぼうずやのにっき

Method getMainLooper in android.os.Looper not mocked

bouzuya/rust-atcoder abc108_c。

難しすぎた。解説を見ても何を言っているのか分からなかった。一応は他のサイトの説明を読んでなるほどと思ったけど自分では解ける気がしない。数学力が足りない。


java.lang.RuntimeException: Method getMainLooper in android.os.Looper not mocked. See http://g.co/androidstudio/not-mocked for details.

MutableLiveData を androidTest ではなく test で使ったら発生した。

https://medium.com/pxhouse/unit-testing-with-mutablelivedata-22b3283a7819

に従って解決した。

まず build.gradledependencies に↓を追加。

testImplementation 'androidx.arch.core:core-testing:2.1.0-rc01'

次に InstantTaskExecutorRuleRule として追加。

@get:Rule
val instantTaskExecutorRule = InstantTaskExecutorRule()

これで通った。


ダ・ヴィンチ・コード』を観た。