quiqua
06/09/2018, 8:44 PMinternal class StatsViewModelSpek : Spek({
describe("a StatsViewModel") {
beforeEachTest {
// Junit Rule to apply
InstantTaskExecutorRule()
}
context("") {
val stats = Stats()
on("create") {
it("should initialize without problems") {
val statsViewModel = StatsViewModel(stats)
}
}
}
}
})
This returns java.lang.RuntimeException: Method getMainLooper in android.os.Looper not mocked
, because I use LiveData
inside that viewModelquiqua
06/09/2018, 8:58 PMInstantTaskExecutorRole()
I added this beforeEachTest {
// Junit Rule to apply
ArchTaskExecutor.getInstance().setDelegate(object : TaskExecutor() {
override fun executeOnDiskIO(runnable: Runnable) {
runnable.run()
}
override fun isMainThread(): Boolean {
return true
}
override fun postToMainThread(runnable: Runnable) {
runnable.run()
}
})
}
and that does the jobquiqua
06/09/2018, 8:59 PMafterEachTest { ArchTaskExecutor.getInstance().setDelegate(null) }
just to be doing the same thing as the rule