From c4c2ea7c263fbade8ffe0a7ccbd4f2fb8946b46f Mon Sep 17 00:00:00 2001 From: Gergely Hegedus Date: Thu, 27 Jan 2022 03:21:55 +0200 Subject: [PATCH] Issue#13 Add separate task for robolectric tests --- ...ouriteContentLocalStorageInstrumentedTest.kt} | 2 +- ...teContentLocalStorageImplInstrumentedTest.kt} | 2 +- ...t.kt => MigrationToLatestInstrumentedTest.kt} | 2 +- ...tyTest.kt => MainActivityInstrumentedTest.kt} | 2 +- ...tyTest.kt => AuthActivityInstrumentedTest.kt} | 2 +- ...Test.kt => SplashActivityInstrumentedTest.kt} | 2 +- build.gradle | 15 --------------- codekata/robolectric.instructionset.md | 2 +- gradlescripts/testoptions.gradle | 16 ++++++++++++++++ 9 files changed, 23 insertions(+), 22 deletions(-) rename app/src/robolectricTest/java/org/fnives/test/showcase/storage/favourite/{CodeKataFavouriteContentLocalStorage.kt => CodeKataFavouriteContentLocalStorageInstrumentedTest.kt} (95%) rename app/src/robolectricTest/java/org/fnives/test/showcase/storage/favourite/{FavouriteContentLocalStorageImplTest.kt => FavouriteContentLocalStorageImplInstrumentedTest.kt} (98%) rename app/src/sharedTest/java/org/fnives/test/showcase/storage/migration/{MigrationToLatest.kt => MigrationToLatestInstrumentedTest.kt} (98%) rename app/src/sharedTest/java/org/fnives/test/showcase/ui/home/{MainActivityTest.kt => MainActivityInstrumentedTest.kt} (99%) rename app/src/sharedTest/java/org/fnives/test/showcase/ui/login/{AuthActivityTest.kt => AuthActivityInstrumentedTest.kt} (99%) rename app/src/sharedTest/java/org/fnives/test/showcase/ui/splash/{SplashActivityTest.kt => SplashActivityInstrumentedTest.kt} (98%) diff --git a/app/src/robolectricTest/java/org/fnives/test/showcase/storage/favourite/CodeKataFavouriteContentLocalStorage.kt b/app/src/robolectricTest/java/org/fnives/test/showcase/storage/favourite/CodeKataFavouriteContentLocalStorageInstrumentedTest.kt similarity index 95% rename from app/src/robolectricTest/java/org/fnives/test/showcase/storage/favourite/CodeKataFavouriteContentLocalStorage.kt rename to app/src/robolectricTest/java/org/fnives/test/showcase/storage/favourite/CodeKataFavouriteContentLocalStorageInstrumentedTest.kt index f84bf89..9ab12ae 100644 --- a/app/src/robolectricTest/java/org/fnives/test/showcase/storage/favourite/CodeKataFavouriteContentLocalStorage.kt +++ b/app/src/robolectricTest/java/org/fnives/test/showcase/storage/favourite/CodeKataFavouriteContentLocalStorageInstrumentedTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Disabled @Disabled("CodeKata") @OptIn(ExperimentalCoroutinesApi::class) -class CodeKataFavouriteContentLocalStorage { +class CodeKataFavouriteContentLocalStorageInstrumentedTest { @Before fun setUp() { diff --git a/app/src/robolectricTest/java/org/fnives/test/showcase/storage/favourite/FavouriteContentLocalStorageImplTest.kt b/app/src/robolectricTest/java/org/fnives/test/showcase/storage/favourite/FavouriteContentLocalStorageImplInstrumentedTest.kt similarity index 98% rename from app/src/robolectricTest/java/org/fnives/test/showcase/storage/favourite/FavouriteContentLocalStorageImplTest.kt rename to app/src/robolectricTest/java/org/fnives/test/showcase/storage/favourite/FavouriteContentLocalStorageImplInstrumentedTest.kt index 479e5f6..b527b76 100644 --- a/app/src/robolectricTest/java/org/fnives/test/showcase/storage/favourite/FavouriteContentLocalStorageImplTest.kt +++ b/app/src/robolectricTest/java/org/fnives/test/showcase/storage/favourite/FavouriteContentLocalStorageImplInstrumentedTest.kt @@ -26,7 +26,7 @@ import org.koin.test.inject @Suppress("TestFunctionName") @OptIn(ExperimentalCoroutinesApi::class) @RunWith(AndroidJUnit4::class) -internal class FavouriteContentLocalStorageImplTest : KoinTest { +internal class FavouriteContentLocalStorageImplInstrumentedTest : KoinTest { private val sut by inject() private lateinit var testDispatcher: TestDispatcher diff --git a/app/src/sharedTest/java/org/fnives/test/showcase/storage/migration/MigrationToLatest.kt b/app/src/sharedTest/java/org/fnives/test/showcase/storage/migration/MigrationToLatestInstrumentedTest.kt similarity index 98% rename from app/src/sharedTest/java/org/fnives/test/showcase/storage/migration/MigrationToLatest.kt rename to app/src/sharedTest/java/org/fnives/test/showcase/storage/migration/MigrationToLatestInstrumentedTest.kt index 75cc71b..d615a49 100644 --- a/app/src/sharedTest/java/org/fnives/test/showcase/storage/migration/MigrationToLatest.kt +++ b/app/src/sharedTest/java/org/fnives/test/showcase/storage/migration/MigrationToLatestInstrumentedTest.kt @@ -25,7 +25,7 @@ import java.io.IOException * https://developer.android.com/training/data-storage/room/migrating-db-versions */ @RunWith(AndroidJUnit4::class) -class MigrationToLatest { +class MigrationToLatestInstrumentedTest { @get:Rule val helper: SharedMigrationTestRule = createSharedMigrationTestRule( diff --git a/app/src/sharedTest/java/org/fnives/test/showcase/ui/home/MainActivityTest.kt b/app/src/sharedTest/java/org/fnives/test/showcase/ui/home/MainActivityInstrumentedTest.kt similarity index 99% rename from app/src/sharedTest/java/org/fnives/test/showcase/ui/home/MainActivityTest.kt rename to app/src/sharedTest/java/org/fnives/test/showcase/ui/home/MainActivityInstrumentedTest.kt index ff4fd8e..eb77d0b 100644 --- a/app/src/sharedTest/java/org/fnives/test/showcase/ui/home/MainActivityTest.kt +++ b/app/src/sharedTest/java/org/fnives/test/showcase/ui/home/MainActivityInstrumentedTest.kt @@ -23,7 +23,7 @@ import org.koin.test.KoinTest @Suppress("TestFunctionName") @RunWith(AndroidJUnit4::class) -class MainActivityTest : KoinTest { +class MainActivityInstrumentedTest : KoinTest { private lateinit var activityScenario: ActivityScenario diff --git a/app/src/sharedTest/java/org/fnives/test/showcase/ui/login/AuthActivityTest.kt b/app/src/sharedTest/java/org/fnives/test/showcase/ui/login/AuthActivityInstrumentedTest.kt similarity index 99% rename from app/src/sharedTest/java/org/fnives/test/showcase/ui/login/AuthActivityTest.kt rename to app/src/sharedTest/java/org/fnives/test/showcase/ui/login/AuthActivityInstrumentedTest.kt index cfa3e78..af9f454 100644 --- a/app/src/sharedTest/java/org/fnives/test/showcase/ui/login/AuthActivityTest.kt +++ b/app/src/sharedTest/java/org/fnives/test/showcase/ui/login/AuthActivityInstrumentedTest.kt @@ -18,7 +18,7 @@ import org.koin.test.KoinTest @Suppress("TestFunctionName") @RunWith(AndroidJUnit4::class) -class AuthActivityTest : KoinTest { +class AuthActivityInstrumentedTest : KoinTest { private lateinit var activityScenario: ActivityScenario diff --git a/app/src/sharedTest/java/org/fnives/test/showcase/ui/splash/SplashActivityTest.kt b/app/src/sharedTest/java/org/fnives/test/showcase/ui/splash/SplashActivityInstrumentedTest.kt similarity index 98% rename from app/src/sharedTest/java/org/fnives/test/showcase/ui/splash/SplashActivityTest.kt rename to app/src/sharedTest/java/org/fnives/test/showcase/ui/splash/SplashActivityInstrumentedTest.kt index 91ab302..50c5359 100644 --- a/app/src/sharedTest/java/org/fnives/test/showcase/ui/splash/SplashActivityTest.kt +++ b/app/src/sharedTest/java/org/fnives/test/showcase/ui/splash/SplashActivityInstrumentedTest.kt @@ -18,7 +18,7 @@ import org.koin.test.KoinTest @Suppress("TestFunctionName") @RunWith(AndroidJUnit4::class) -class SplashActivityTest : KoinTest { +class SplashActivityInstrumentedTest : KoinTest { private lateinit var activityScenario: ActivityScenario diff --git a/build.gradle b/build.gradle index d96f97a..9c84311 100644 --- a/build.gradle +++ b/build.gradle @@ -29,21 +29,6 @@ task clean(type: Delete) { delete rootProject.buildDir } -task unitTests(dependsOn: ["app:testDebugUnitTest", "core:test", "network:test"]){ - group = 'Tests' - description = 'Run all unit tests' -} - -task robolectricTests(dependsOn: ["app:testDebugUnitTest"]){ - group = 'Tests' - description = 'Run all robolectric tests' -} - -task androidTests(dependsOn: ["app:connectedDebugAndroidTest"]){ - group = 'Tests' - description = 'Run all Android tests' -} - apply from: 'gradlescripts/versions.gradle' apply from: 'gradlescripts/detekt.config.gradle' apply from: 'gradlescripts/ktlint.gradle' diff --git a/codekata/robolectric.instructionset.md b/codekata/robolectric.instructionset.md index 3c3aab5..1889fad 100644 --- a/codekata/robolectric.instructionset.md +++ b/codekata/robolectric.instructionset.md @@ -23,7 +23,7 @@ What it does is: So let's start with the setup. -Our test class is `org.fnives.test.showcase.storage.favourite.CodeKataFavouriteContentLocalStorage` +Our test class is `org.fnives.test.showcase.storage.favourite.CodeKataFavouriteContentLocalStorageInstrumentedTest` Question: Why don't we test the DAO and Storage separately using mocking? Answer: The same logic applies how we didn't test the RetrofitServices just the RemoteSources. The Service just like the DAO is an implementation detail, our code only accesses them through the RemoteSource / LocalStorage abstraction. With this in mind now we only want to test that we interact with the database properly, we don't really care how many DAOs are used. diff --git a/gradlescripts/testoptions.gradle b/gradlescripts/testoptions.gradle index 7193f48..9c0e171 100644 --- a/gradlescripts/testoptions.gradle +++ b/gradlescripts/testoptions.gradle @@ -62,4 +62,20 @@ subprojects { module -> } } } +} + +task jvmTests(dependsOn: ["app:testDebugUnitTest", "core:test", "network:test"]) { + group = 'Tests' + description = 'Run all JVM tests' +} + +task robolectricTests(type: Exec) { + group = 'Tests' + description = 'Run all Robolectric tests based on the Instrumented naming convention' + commandLine 'sh', './gradlew', 'testDebugUnitTest', '--tests', 'org.fnives.test.*InstrumentedTest' +} + +task androidTests(dependsOn: ["app:connectedDebugAndroidTest"]) { + group = 'Tests' + description = 'Run Android tests' } \ No newline at end of file