Test a Data Access Object (DAO)

Testing a DAO takes some extra work in addition to what we did in the previous two classes, as now we’re dealing with Room. Also, this is the first time we’re going to be making instrumented tests or tests that run on an Android device, either a real device or an emulator. While working with a Room DB doesn’t require you to run the test on a device, doing so makes sure you’re using the same version of SQLite from an Android device. If you run these tests on your local machine, you may see errors that wouldn’t actually happen on the app.

Writing instrumented tests has a downside, though. They’re significantly slower since you have to wait for the device to be ready and the test to be deployed out to the device. ...

Get Kotlin and Android Development featuring Jetpack now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.