Issue#13 Add separate task for robolectric tests

This commit is contained in:
Gergely Hegedus 2022-01-27 03:21:55 +02:00
parent f248ab1081
commit c4c2ea7c26
9 changed files with 23 additions and 22 deletions

View file

@ -9,7 +9,7 @@ import org.junit.jupiter.api.Disabled
@Disabled("CodeKata") @Disabled("CodeKata")
@OptIn(ExperimentalCoroutinesApi::class) @OptIn(ExperimentalCoroutinesApi::class)
class CodeKataFavouriteContentLocalStorage { class CodeKataFavouriteContentLocalStorageInstrumentedTest {
@Before @Before
fun setUp() { fun setUp() {

View file

@ -26,7 +26,7 @@ import org.koin.test.inject
@Suppress("TestFunctionName") @Suppress("TestFunctionName")
@OptIn(ExperimentalCoroutinesApi::class) @OptIn(ExperimentalCoroutinesApi::class)
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
internal class FavouriteContentLocalStorageImplTest : KoinTest { internal class FavouriteContentLocalStorageImplInstrumentedTest : KoinTest {
private val sut by inject<FavouriteContentLocalStorage>() private val sut by inject<FavouriteContentLocalStorage>()
private lateinit var testDispatcher: TestDispatcher private lateinit var testDispatcher: TestDispatcher

View file

@ -25,7 +25,7 @@ import java.io.IOException
* https://developer.android.com/training/data-storage/room/migrating-db-versions * https://developer.android.com/training/data-storage/room/migrating-db-versions
*/ */
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
class MigrationToLatest { class MigrationToLatestInstrumentedTest {
@get:Rule @get:Rule
val helper: SharedMigrationTestRule = createSharedMigrationTestRule<LocalDatabase>( val helper: SharedMigrationTestRule = createSharedMigrationTestRule<LocalDatabase>(

View file

@ -23,7 +23,7 @@ import org.koin.test.KoinTest
@Suppress("TestFunctionName") @Suppress("TestFunctionName")
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
class MainActivityTest : KoinTest { class MainActivityInstrumentedTest : KoinTest {
private lateinit var activityScenario: ActivityScenario<MainActivity> private lateinit var activityScenario: ActivityScenario<MainActivity>

View file

@ -18,7 +18,7 @@ import org.koin.test.KoinTest
@Suppress("TestFunctionName") @Suppress("TestFunctionName")
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
class AuthActivityTest : KoinTest { class AuthActivityInstrumentedTest : KoinTest {
private lateinit var activityScenario: ActivityScenario<AuthActivity> private lateinit var activityScenario: ActivityScenario<AuthActivity>

View file

@ -18,7 +18,7 @@ import org.koin.test.KoinTest
@Suppress("TestFunctionName") @Suppress("TestFunctionName")
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
class SplashActivityTest : KoinTest { class SplashActivityInstrumentedTest : KoinTest {
private lateinit var activityScenario: ActivityScenario<SplashActivity> private lateinit var activityScenario: ActivityScenario<SplashActivity>

View file

@ -29,21 +29,6 @@ task clean(type: Delete) {
delete rootProject.buildDir 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/versions.gradle'
apply from: 'gradlescripts/detekt.config.gradle' apply from: 'gradlescripts/detekt.config.gradle'
apply from: 'gradlescripts/ktlint.gradle' apply from: 'gradlescripts/ktlint.gradle'

View file

@ -23,7 +23,7 @@ What it does is:
So let's start with the setup. 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? 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. 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.

View file

@ -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'
} }