Step #6: Fixing the Existing Tests

At this point, some of our tests are broken, due to changes to the ToDoRepository constructor.

In RosterListFragmentTest (in the androidTest/ source set), in the setUp() function, replace our existing ToDoRepository setup with:

    repo = ToDoRepository(
      db.todoStore(),
      appScope,
      ToDoRemoteDataSource(OkHttpClient())
    )

This creates a valid ToDoRemoteDataSource, using a one-off copy of an OkHttpClient. Since we are not testing the import process here, these objects will not be used — they are just here to satisfy the compiler.

Then, in ToDoRepositoryTest (in the androidTest/ source set), add a new property for an implementation of ToDoRemoteDataSource:

  private val remoteDataSource = ToDoRemoteDataSource(OkHttpClient())

We can use a real implementation of ToDoRemoteDataSource and OkHttpClient here, as neither of those depend on Android — they work fine in a regular Kotlin/JVM environment.

Then, modify each underTest in ToDoRepositoryTest to pass that ToDoRemoteDataSource to our ToDoRepository constructor:

    val underTest = ToDoRepository(db.todoStore(), this, remoteDataSource)

There are three of these, one for each test function.

And, if you run RosterListFragmentTest and ToDoRepositoryTest now, they should pass.


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.