From the course: Building an Android App with Jetpack Libraries

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Create a unit test for database logic

Create a unit test for database logic - Android Tutorial

From the course: Building an Android App with Jetpack Libraries

Start my 1-month free trial

Create a unit test for database logic

- Before, continuing my work on the app, I want to test my database logic with an Android JUnit test. First, I'm going to add another function to my data access object, to report how many rows there are in the notes database. I'll create a new query and I'll set the SQL statement to look like this. Select count of asterisk from, and then the notes table. And I'll set that as a function called get count and it'll return an integer. So now I'll be able to easily query the database table and find out how many rows there are. Next I'll go over to the project window and I'll go to this version of the base package, that's labeled Android test, and I'll open this class named example instrumented test that was created for me. This is an example of a JUnit test. Now I'm going to leave this sample code alone, so I'm going to copy and then paste to create a new class, and I'll call this one database test. I'll get rid of these…

Contents