Writing your first test

Locate the root package of your unit tests and create a new class called NoteTest as follows:

    package com.journaler 
    import android.location.Location 
    import com.journaler.database.Content 
    import com.journaler.model.Note 
    import org.junit.Test 
    class NoteTest { 
      fun noteTest() { 
        val note = Note( 
                "stub ${System.currentTimeMillis()}", 
                "stub ${System.currentTimeMillis()}", 
        val id = Content.NOTE.insert(note) 
        note.id = id 
        assert(note.id > 0) 

The test is very simple. It creates a new instance of Note, triggers the CRUD operation in our content provider to store it, and verifies the ID received. To run the test, right-click on class from the Project pane and choose Run 'NoteTest':

The unit test ...

Get Mastering Android Development with Kotlin now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.