Testing Android Architecture Components | raywenderlich.com

Learn how to test the Architecture Components library included in the Android Jetpack suite released in 2017 by Google’s Android Team.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/12678525-testing-android-architecture-components

Hi Enzo,
Thanks for the tutorial.

I just wanted to warn that this function is missing in the tutorial. It is called but never defined.

@Throws(InterruptedException::class)
fun <T> LiveData<T>.getValueBlocking(): T? {
    var value: T? = null
    val latch = CountDownLatch(1)
    val innerObserver = Observer<T> {
        value = it
        latch.countDown()
    }
    observeForever(innerObserver)
    latch.await(2, TimeUnit.SECONDS)
    return value
}

Have a nice day.