diff --git a/app/build.gradle b/app/build.gradle index b6beea9..214a08b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -101,46 +101,10 @@ dependencies { implementation project(":core") - testImplementation "androidx.room:room-testing:$androidx_room_version" - testImplementation "org.junit.jupiter:junit-jupiter-engine:$testing_junit5_version" - testImplementation "org.junit.jupiter:junit-jupiter-params:$testing_junit5_version" - testImplementation "org.mockito.kotlin:mockito-kotlin:$testing_kotlin_mockito_version" - testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version" - testImplementation "com.jraska.livedata:testing-ktx:$testing_livedata_version" - testImplementation "io.insert-koin:koin-test-junit5:$koin_version" - testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$testing_junit5_version" + applyAppTestDependenciesTo(this) + applyComposeTestDependenciesTo(this) - // robolectric specific - testImplementation "junit:junit:$testing_junit4_version" - testImplementation "org.robolectric:robolectric:$testing_robolectric_version" - testImplementation "androidx.test:core:$testing_androidx_code_version" - testImplementation "androidx.test:runner:$testing_androidx_code_version" - testImplementation "androidx.test.ext:junit:$testing_androidx_junit_version" - testImplementation "androidx.test.espresso:espresso-core:$testing_espresso_version" - testImplementation "androidx.test.espresso:espresso-intents:$testing_espresso_version" - testImplementation "androidx.test.espresso:espresso-contrib:$testing_espresso_version" - testImplementation project(':mockserver') - testImplementation "androidx.arch.core:core-testing:$testing_androidx_arch_core_version" - testRuntimeOnly "org.junit.vintage:junit-vintage-engine:$testing_junit5_version" - - androidTestImplementation "androidx.room:room-testing:$androidx_room_version" - androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version" - androidTestImplementation "io.insert-koin:koin-test-junit4:$koin_version" - androidTestImplementation "junit:junit:$testing_junit4_version" - androidTestImplementation "androidx.test:core:$testing_androidx_code_version" - androidTestImplementation "androidx.test:runner:$testing_androidx_code_version" - androidTestImplementation "androidx.test.ext:junit:$testing_androidx_junit_version" - androidTestImplementation "androidx.test.espresso:espresso-core:$testing_espresso_version" - androidTestImplementation "androidx.test.espresso:espresso-intents:$testing_espresso_version" - androidTestImplementation "androidx.test.espresso:espresso-contrib:$testing_espresso_version" - androidTestImplementation "androidx.compose.ui:ui-test-junit4:$androidx_compose_version" - testImplementation "androidx.compose.ui:ui-test-junit4:$androidx_compose_version" - debugImplementation "androidx.compose.ui:ui-test-manifest:$androidx_compose_version" androidTestImplementation project(':mockserver') - androidTestImplementation "androidx.arch.core:core-testing:$testing_androidx_arch_core_version" - androidTestRuntimeOnly "org.junit.vintage:junit-vintage-engine:$testing_junit5_version" - - implementation "io.reactivex.rxjava3:rxjava:3.1.4" testImplementation testFixtures(project(':core')) androidTestImplementation testFixtures(project(':core')) diff --git a/build.gradle b/build.gradle index a04b51e..0e88155 100644 --- a/build.gradle +++ b/build.gradle @@ -34,4 +34,5 @@ apply from: 'gradlescripts/detekt.config.gradle' apply from: 'gradlescripts/ktlint.gradle' apply from: 'gradlescripts/lint.gradle' apply from: 'gradlescripts/testoptions.gradle' -apply from: 'gradlescripts/test.tasks.gradle' \ No newline at end of file +apply from: 'gradlescripts/test.tasks.gradle' +apply from: 'gradlescripts/testdependencies.gradle' \ No newline at end of file diff --git a/core/build.gradle b/core/build.gradle index 617bb40..ebc50e5 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -20,15 +20,7 @@ dependencies { api project(":model") implementation project(":network") - testImplementation "io.insert-koin:koin-test-junit5:$koin_version" - testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version" - testImplementation "org.mockito.kotlin:mockito-kotlin:$testing_kotlin_mockito_version" - testImplementation "org.junit.jupiter:junit-jupiter-engine:$testing_junit5_version" - testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$testing_junit5_version" - testImplementation "com.squareup.retrofit2:retrofit:$retrofit_version" - testImplementation "app.cash.turbine:turbine:$turbine_version" - - testImplementation "org.junit.jupiter:junit-jupiter-params:$testing_junit5_version" + applyCoreTestDependenciesTo(this) testImplementation project(':mockserver') testFixturesApi testFixtures(project(':network')) diff --git a/gradlescripts/testdependencies.gradle b/gradlescripts/testdependencies.gradle new file mode 100644 index 0000000..428a4cd --- /dev/null +++ b/gradlescripts/testdependencies.gradle @@ -0,0 +1,146 @@ +project.ext { + + /* + ------------------USAGE------------------ + add line in root build.gradle: + apply from: 'gradlescripts/testdependencies.gradle' (this file) + then in your modules you can use: + + ------------------NETWORK(Java Module)------------------ + dependencies { + applyNetworkTestDependenciesTo(this) + } + + ------------------CORE(Java Module)------------------ + dependencies { + applyCoreTestDependenciesTo(this) + } + + ------------------APP(Android Module)------------------ + dependencies { + applyAppTestDependenciesTo(this) + applyComposeTestDependenciesTo(this) // if you are using compose + } + + ------------------VERSIONS------------------ + versions try to get the global value, if not found they fall back to some defaults. + You can find them just below + */ + + def propertyOrNull = { key -> + if (hasProperty(key)) { + return property(key) + } else { + return null + } + } + + // ------------------VERSIONS------------------ + def testing_junit5_version = propertyOrNull('junit5_version') ?: "5.7.0" + def testing_junit4_version = propertyOrNull('juni4_version') ?: "4.13.2" + def testing_robolectric_version = propertyOrNull('robolectric_version') ?: "4.7" + def testing_androidx_code_version = propertyOrNull('androidx_test_version') ?: "1.4.0" + def testing_androidx_junit_version = propertyOrNull('androidx_junit_version') ?: "1.1.3" + def testing_espresso_version = propertyOrNull('espresso_version') ?: "3.4.0" + def testing_androidx_arch_core_version = propertyOrNull('androidx_arch_version') ?: "2.1.0" + def test_coroutines_version = propertyOrNull('coroutines_versionx') ?: "1.6.0" + def testing_kotlin_mockito_version = propertyOrNull('mockito_version') ?: "3.1.0" + def testing_koin_version = propertyOrNull('koin_version') ?: "3.1.2" + def testing_json_assert_version = propertyOrNull('json_assert_version') ?: "1.5.0" + def testing_okhttp3 = propertyOrNull('okhttp_version') ?: "4.9.3" + def testing_turbine_version = propertyOrNull('turbine_version') ?: "0.7.0" + def testing_androidx_room_version = propertyOrNull('room_version') ?: "2.4.1" + def testing_livedata_version = propertyOrNull('testing_livedata_version') ?: "1.2.0" + def testing_compose_version = propertyOrNull('compose_version') ?: "1.1.0" + + // ------------------PRIVATE------------------ + // JUni4 + Espresso + Room + def androidSpecificTestDependencies = [ + "junit:junit:$testing_junit4_version", + + "androidx.room:room-testing:$testing_androidx_room_version", + + "com.jraska.livedata:testing-ktx:$testing_livedata_version", + + "androidx.test:core:$testing_androidx_code_version", + "androidx.test:runner:$testing_androidx_code_version", + + "androidx.test.ext:junit:$testing_androidx_junit_version", + + "androidx.test.espresso:espresso-core:$testing_espresso_version", + "androidx.test.espresso:espresso-intents:$testing_espresso_version", + "androidx.test.espresso:espresso-contrib:$testing_espresso_version", + + "androidx.arch.core:core-testing:$testing_androidx_arch_core_version", + ] + + // ------------------PRIVATE------------------ + def applyStandardTestDependenciesTo = { module -> + module.dependencies { + // coroutine testing + testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$test_coroutines_version" + + // mockito, mocking library + testImplementation "org.mockito.kotlin:mockito-kotlin:$testing_kotlin_mockito_version" + + testImplementation "io.insert-koin:koin-test-junit5:$testing_koin_version" + // junit5 + testImplementation "org.junit.jupiter:junit-jupiter-engine:$testing_junit5_version" + testImplementation "org.junit.jupiter:junit-jupiter-params:$testing_junit5_version" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$testing_junit5_version" + } + } + + // ------------------NETWORK------------------ + applyNetworkTestDependenciesTo = { module -> + applyStandardTestDependenciesTo(module) + + module.dependencies { + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$testing_junit5_version" + // JSON Assert + testImplementation "org.skyscreamer:jsonassert:$testing_json_assert_version" + + // mockwebserver + https support + testImplementation "com.squareup.okhttp3:mockwebserver:$testing_okhttp3" + testImplementation "com.squareup.okhttp3:okhttp-tls:$testing_okhttp3" + } + } + + // ------------------CORE------------------ + applyCoreTestDependenciesTo = { module -> + applyStandardTestDependenciesTo(module) + + module.dependencies { + // turbine, flow testing + testImplementation "app.cash.turbine:turbine:$testing_turbine_version" + } + } + + // ------------------APP------------------ + applyAppTestDependenciesTo = { module -> + applyStandardTestDependenciesTo(module) + + module.dependencies { + testImplementation "org.robolectric:robolectric:$testing_robolectric_version" + testRuntimeOnly "org.junit.vintage:junit-vintage-engine:$testing_junit5_version" + + androidSpecificTestDependencies.forEach { dependency -> + testImplementation dependency + androidTestImplementation dependency + } + + androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$test_coroutines_version" + androidTestImplementation "io.insert-koin:koin-test-junit5:$testing_koin_version" + androidTestRuntimeOnly "org.junit.vintage:junit-vintage-engine:$testing_junit5_version" + } + } + + // ------------------COMPOSE------------------ + applyComposeTestDependenciesTo = { module -> + module.dependencies { + testImplementation "androidx.compose.ui:ui-test-junit4:$testing_compose_version" + androidTestImplementation "androidx.compose.ui:ui-test-junit4:$testing_compose_version" + debugImplementation "androidx.compose.ui:ui-test-manifest:$testing_compose_version" + } + } +} \ No newline at end of file diff --git a/network/build.gradle b/network/build.gradle index e8cf19c..ed5e6f7 100644 --- a/network/build.gradle +++ b/network/build.gradle @@ -24,10 +24,7 @@ dependencies { api project(":model") - testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version" - testImplementation "org.mockito.kotlin:mockito-kotlin:$testing_kotlin_mockito_version" - testImplementation "org.skyscreamer:jsonassert:$testing_json_assert_version" - testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$testing_junit5_version" + applyNetworkTestDependenciesTo(this) testFixturesApi project(':mockserver') testFixturesApi "org.junit.jupiter:junit-jupiter-engine:$testing_junit5_version"