# Testing LiveData in JUnit 4 and JUnit 5

DevFeed: [Testing LiveData in JUnit 4 and JUnit 5](<https://devfeed.tech/articles/testing-livedata-in-junit-4-and-junit-5-28675.md>)

Original publisher: [Read original article](<https://jeroenmols.com/blog/2019/01/17/livedatajunit5/>)

Author: info@jeroenmols.com (Jeroen Mols)

Published: 2019-01-17T00:00:00Z

Content type: tutorial

Language: en

Sources: [Jeroen Mols](<https://devfeed.tech/sources/jeroen-mols.md>)

Topics: [Testing](<https://devfeed.tech/topics/testing.md>), [Android](<https://devfeed.tech/topics/android.md>), [test](<https://devfeed.tech/topics/test.md>), [unit tests](<https://devfeed.tech/topics/unit-tests.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [architecture](<https://devfeed.tech/tags/architecture.md>), [architecture-components](<https://devfeed.tech/tags/architecture-components.md>), [blogs](<https://devfeed.tech/tags/blogs.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [junit](<https://devfeed.tech/tags/junit.md>), [livedata](<https://devfeed.tech/tags/livedata.md>), [testing](<https://devfeed.tech/tags/testing.md>), [unit-test](<https://devfeed.tech/tags/unit-test.md>), [unit-tests](<https://devfeed.tech/tags/unit-tests.md>), [viewmodel](<https://devfeed.tech/tags/viewmodel.md>)

## AI overview

A tutorial on testing Android LiveData with JUnit 4 and JUnit 5. It explains why JVM unit tests cannot use Android's main thread directly and shows how JUnit rules or JUnit 5 extensions can update LiveData synchronously on the calling thread.

## Source excerpt

Architecture components are one of the most exciting things that happened to Android in the past years. But how do you effectively go about and testing this?