From d87d37a163d30220b75803405c9738e3dde1802e Mon Sep 17 00:00:00 2001 From: Gergely Hegedus Date: Thu, 30 Jun 2022 15:41:06 +0300 Subject: [PATCH 1/3] Issue#90 Fix Issue with the order of commands for Koin Re-initialization --- codekata/sharedtests.instructionset.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/codekata/sharedtests.instructionset.md b/codekata/sharedtests.instructionset.md index 9af368a..b8e0065 100644 --- a/codekata/sharedtests.instructionset.md +++ b/codekata/sharedtests.instructionset.md @@ -132,7 +132,7 @@ This is great if you want to have End-to-End tests that follow each other, but s We will check if koin is initialized, if it isn't then we simply initialize it: ```kotlin ... -TestDatabaseInitialization.overwriteDatabaseInitialization(dispatcher) +Intents.init() if (GlobalContext.getOrNull() == null) { val application = ApplicationProvider.getApplicationContext() val baseUrl = BaseUrl(BuildConfig.BASE_URL) @@ -140,7 +140,8 @@ if (GlobalContext.getOrNull() == null) { androidContext(application) modules(createAppModules(baseUrl)) } -} +} // needs to be before the Database overwriting +val dispatcher = StandardTestDispatcher() ... ``` From 24bef1ba3ea81e62c448a91fef30ea374f9d3acc Mon Sep 17 00:00:00 2001 From: Gergely Hegedus Date: Thu, 30 Jun 2022 15:42:08 +0300 Subject: [PATCH 2/3] Issue#90 Update documentation of TestDatabaseInitialization --- .../showcase/testutils/storage/TestDatabaseInitialization.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/storage/TestDatabaseInitialization.kt b/app/src/sharedTest/java/org/fnives/test/showcase/testutils/storage/TestDatabaseInitialization.kt index fe70364..7e745dd 100644 --- a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/storage/TestDatabaseInitialization.kt +++ b/app/src/sharedTest/java/org/fnives/test/showcase/testutils/storage/TestDatabaseInitialization.kt @@ -11,6 +11,9 @@ import org.koin.dsl.module /** * Reloads the Database Koin module, so it uses the inMemory database with the switched out Executors. + * + * This is needed so in AndroidTests not a real File based device is used. + * This speeds tests up, and isolates them better, there will be no junk in the Database file from previous tests. */ object TestDatabaseInitialization { From e39529b9e0adf7f91c02e4915a9229070cffc4fc Mon Sep 17 00:00:00 2001 From: Gergely Hegedus Date: Thu, 30 Jun 2022 15:48:15 +0300 Subject: [PATCH 3/3] Issue#89 Note how users can try out Record Espresso Test tool Point out that current Compose projects cannot do this. Note to the reader a branch on which they can freely start experimenting with Espresso Test Recording. --- codekata/sharedtests.instructionset.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/codekata/sharedtests.instructionset.md b/codekata/sharedtests.instructionset.md index b8e0065..4fc3937 100644 --- a/codekata/sharedtests.instructionset.md +++ b/codekata/sharedtests.instructionset.md @@ -12,7 +12,7 @@ In this testing instruction set you will learn how to write simple tests running - We will use RuleChains to order our Test Rules. ## Login UI Test -Instead of writing new tests from scratch, we will modify our existing Robolectric tests so they can be run on a Real Android device as well. +Instead of writing new tests from scratch, we will modify our existing Robolectric tests so they can be run on a Real Android device as well.N For this we already have a `sharedTest` package. Our classes will be `CodeKataAuthActivitySharedTest` and `CodeKataSharedRobotTest`. @@ -347,6 +347,10 @@ You might be thinking, then why did we go through how to do these stuff manually All in all, it is a good tool to get started on your test, but you probably still need to do manual modifications on it. So personally I would suggest them for bigger tests, which would take too much time manually, and then do the adjustments while running the tests. +> **Note: If you try it now, it will state that it is not compatible with Compose Projects.** +> So first switch to branch `TEST-HERE-Record-Espresso-Test` or commit `694d1bf0e71e40e80de849a3a6bb5e8a3430e348`. +> This is the last commit that still had no compose in it. + Okay, but how do we do it? As it's written on the site, we select `Run > Record Espresso Test`. This will start the application on your device and you can do interactions with it. Such as writing into a text input.