From 88b122e0b7e476af31b759f7e87cb61cd04fd8e5 Mon Sep 17 00:00:00 2001 From: Gergely Hegedus Date: Mon, 7 Feb 2022 11:05:02 +0200 Subject: [PATCH] PR#57 Explain how DatabaseInitialization is overwritten --- codekata/robolectric.instructionset.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/codekata/robolectric.instructionset.md b/codekata/robolectric.instructionset.md index ae3da0c..9f4ffb0 100644 --- a/codekata/robolectric.instructionset.md +++ b/codekata/robolectric.instructionset.md @@ -208,6 +208,9 @@ fun atTheStartOurDatabaseIsEmpty()= runTest(testDispatcher) { The line `DatabaseInitialization.dispatcher = testDispatcher` may look a bit mysterious, but all we do with it is to overwrite our original DatabaseInitialization in tests, and use the given Dispatcher as an executor for Room setup. +> DatabaseInitialization is overwritten in the Test module, by declaring the same class in the same package with the same methods. This is an easy way to switch out an implementation. +> This might not look the cleanest, so an alternative way is to switch out the koin-module of how to create the database. For this we could use loadKoinModules. In other dependency injection / service locator frameworks this should also be possible. + ### 1. `atTheStartOurDatabaseIsEmpty` Our test is as simple as it gets. We get the observable and it's first element. Then we assert that it is an empty list.