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.

Solution: Add another unit test for database logic

Solution: Add another unit test for database logic - Android Tutorial

From the course: Building an Android App with Jetpack Libraries

Start my 1-month free trial

Solution: Add another unit test for database logic

(upbeat music) - [Instructor] For this challenge, I asked you to create a new test for your database. Create a note object, set its text value and insert it into the database. Then retrieve the data based on the expected primary key or unique ID of one, for the first row in the database table, then compare the ID to the expected value and if those values match, then the test succeeds. Here's my solution, I'll create a new test function and I'll name it insertNote, the name of the function could be anything you want. Next I'll create a new Note object using the note entity classes, no arguments constructor. Then I'll set the notes text property to anything. It'll just be some text then out insert that note object into the database using dao dot insert note and I'll pass in the note object. Next, I'll retrieve that note from the database table. I'll create a new variable that I'll call saved note and I'll use dao…

Contents