java.lang.RuntimeException: Method getMainLooper in android.os.Looper not mocked. See http://g.co/androidstudio/not-mocked for details.
at android.os.Looper.getMainLooper(Looper.java)
at android.arch.core.executor.DefaultTaskExecutor.isMainThread(DefaultTaskExecutor.java:58)
at android.arch.core.executor.AppToolkitTaskExecutor.isMainThread(AppToolkitTaskExecutor.java:115)
at android.arch.lifecycle.LiveData.assertMainThread(LiveData.java:408)
at android.arch.lifecycle.LiveData.setValue(LiveData.java:290)
at android.arch.lifecycle.MutableLiveData.setValue(MutableLiveData.java:33)
at pl.pbochenski.archcomponentstest.MainViewModelTest.shouldGetPostsAndHaveACopyOfIt(MainViewModelTest.kt:48) ...
Last active
April 10, 2018 18:16
-
-
Save pbochenski/e9aef99158003f70f273cf0e2b9d43b0 to your computer and use it in GitHub Desktop.
testing LiveData
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
testCompile("android.arch.core:core-testing:$archVersion", { | |
exclude group: 'com.android.support', module: 'support-compat' | |
exclude group: 'com.android.support', module: 'support-annotations' | |
exclude group: 'com.android.support', module: 'support-core-utils' | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainViewModelTest { | |
@Rule | |
@JvmField | |
val rule = InstantTaskExecutorRule() | |
@Test | |
fun someTest(){ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun shouldGetPostsAfterUpdate() { | |
//given | |
val returnedItem = createDummyItem() | |
val observer = mock<Observer<List<Post>>>() | |
model.getPosts().observeForever(observer) | |
//when | |
liveData.value = listOf(returnedItem) | |
//than | |
verify(observer).onChanged(listOf(Post(returnedItem.id, returnedItem.title, returnedItem.url))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@pbochenski, it should be
then
instead ofthan
.