diff --git a/app/build.gradle b/app/build.gradle index 37ae54c..85095b1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -107,10 +107,11 @@ dependencies { androidTestImplementation project(':mockserver') testImplementation testFixtures(project(':core')) + testImplementation project(':test-util-junit5-android') androidTestImplementation testFixtures(project(':core')) - implementation project(':test-util-shared-robolectric') + testImplementation project(':test-util-shared-robolectric') androidTestImplementation project(':test-util-shared-android') - implementation project(':test-util-android') + testImplementation project(':test-util-android') androidTestImplementation project(':test-util-android') } diff --git a/app/src/test/java/org/fnives/test/showcase/ui/auth/AuthViewModelTest.kt b/app/src/test/java/org/fnives/test/showcase/ui/auth/AuthViewModelTest.kt index 64570b3..70767f5 100644 --- a/app/src/test/java/org/fnives/test/showcase/ui/auth/AuthViewModelTest.kt +++ b/app/src/test/java/org/fnives/test/showcase/ui/auth/AuthViewModelTest.kt @@ -3,11 +3,11 @@ package org.fnives.test.showcase.ui.auth import com.jraska.livedata.test import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking +import org.fnives.test.showcase.android.testutil.InstantExecutorExtension import org.fnives.test.showcase.core.login.LoginUseCase import org.fnives.test.showcase.model.auth.LoginCredentials import org.fnives.test.showcase.model.auth.LoginStatus import org.fnives.test.showcase.model.shared.Answer -import org.fnives.test.showcase.testutils.InstantExecutorExtension import org.fnives.test.showcase.testutils.TestMainDispatcher import org.fnives.test.showcase.ui.shared.Event import org.junit.jupiter.api.BeforeEach diff --git a/app/src/test/java/org/fnives/test/showcase/ui/auth/CodeKataAuthViewModel.kt b/app/src/test/java/org/fnives/test/showcase/ui/auth/CodeKataAuthViewModel.kt index 7a70ed0..4de4386 100644 --- a/app/src/test/java/org/fnives/test/showcase/ui/auth/CodeKataAuthViewModel.kt +++ b/app/src/test/java/org/fnives/test/showcase/ui/auth/CodeKataAuthViewModel.kt @@ -1,8 +1,8 @@ package org.fnives.test.showcase.ui.auth import kotlinx.coroutines.ExperimentalCoroutinesApi +import org.fnives.test.showcase.android.testutil.InstantExecutorExtension import org.fnives.test.showcase.core.login.LoginUseCase -import org.fnives.test.showcase.testutils.InstantExecutorExtension import org.fnives.test.showcase.testutils.TestMainDispatcher import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.DisplayName diff --git a/app/src/test/java/org/fnives/test/showcase/ui/home/MainViewModelTest.kt b/app/src/test/java/org/fnives/test/showcase/ui/home/MainViewModelTest.kt index e0ca3e8..6173944 100644 --- a/app/src/test/java/org/fnives/test/showcase/ui/home/MainViewModelTest.kt +++ b/app/src/test/java/org/fnives/test/showcase/ui/home/MainViewModelTest.kt @@ -4,6 +4,7 @@ import com.jraska.livedata.test import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.runBlocking +import org.fnives.test.showcase.android.testutil.InstantExecutorExtension import org.fnives.test.showcase.core.content.AddContentToFavouriteUseCase import org.fnives.test.showcase.core.content.FetchContentUseCase import org.fnives.test.showcase.core.content.GetAllContentUseCase @@ -14,7 +15,6 @@ import org.fnives.test.showcase.model.content.ContentId import org.fnives.test.showcase.model.content.FavouriteContent import org.fnives.test.showcase.model.content.ImageUrl import org.fnives.test.showcase.model.shared.Resource -import org.fnives.test.showcase.testutils.InstantExecutorExtension import org.fnives.test.showcase.testutils.TestMainDispatcher import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.DisplayName diff --git a/app/src/test/java/org/fnives/test/showcase/ui/splash/SplashViewModelTest.kt b/app/src/test/java/org/fnives/test/showcase/ui/splash/SplashViewModelTest.kt index bd366e1..01d59f1 100644 --- a/app/src/test/java/org/fnives/test/showcase/ui/splash/SplashViewModelTest.kt +++ b/app/src/test/java/org/fnives/test/showcase/ui/splash/SplashViewModelTest.kt @@ -2,8 +2,8 @@ package org.fnives.test.showcase.ui.splash import com.jraska.livedata.test import kotlinx.coroutines.ExperimentalCoroutinesApi +import org.fnives.test.showcase.android.testutil.InstantExecutorExtension import org.fnives.test.showcase.core.login.IsUserLoggedInUseCase -import org.fnives.test.showcase.testutils.InstantExecutorExtension import org.fnives.test.showcase.testutils.TestMainDispatcher import org.fnives.test.showcase.ui.shared.Event import org.junit.jupiter.api.BeforeEach diff --git a/gradlescripts/versions.gradle b/gradlescripts/versions.gradle index 031de2a..5362774 100644 --- a/gradlescripts/versions.gradle +++ b/gradlescripts/versions.gradle @@ -26,7 +26,7 @@ project.ext { arch_core_version = "2.1.0" testing_livedata_version = "1.2.0" testing_kotlin_mockito_version = "4.0.0" - testing_junit5_version = "5.7.0" + junit5_version = "5.7.0" testing_json_assert_version = "1.5.0" testing_junit4_version = "4.12" testing_robolectric_version = "4.7" diff --git a/network/build.gradle b/network/build.gradle index ed5e6f7..db2bc59 100644 --- a/network/build.gradle +++ b/network/build.gradle @@ -27,6 +27,6 @@ dependencies { applyNetworkTestDependenciesTo(this) testFixturesApi project(':mockserver') - testFixturesApi "org.junit.jupiter:junit-jupiter-engine:$testing_junit5_version" + testFixturesApi "org.junit.jupiter:junit-jupiter-engine:$junit5_version" testFixturesApi "io.insert-koin:koin-test-junit5:$koin_version" } \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 7e8bd01..6b11768 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,3 +7,4 @@ include ':app' include ':test-util-shared-android' include ':test-util-shared-robolectric' include ':test-util-android' +include ':test-util-junit5-android' diff --git a/test-util-junit5-android/.gitignore b/test-util-junit5-android/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/test-util-junit5-android/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/test-util-junit5-android/build.gradle b/test-util-junit5-android/build.gradle new file mode 100644 index 0000000..dd13d96 --- /dev/null +++ b/test-util-junit5-android/build.gradle @@ -0,0 +1,35 @@ +plugins { + id 'com.android.library' + id 'org.jetbrains.kotlin.android' +} + +android { + compileSdk 31 + + defaultConfig { + minSdk 21 + targetSdk 31 + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles "consumer-rules.pro" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + implementation "org.junit.jupiter:junit-jupiter-engine:$junit5_version" + implementation "androidx.arch.core:core-runtime:$arch_core_version" +} \ No newline at end of file diff --git a/test-util-junit5-android/consumer-rules.pro b/test-util-junit5-android/consumer-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/test-util-junit5-android/proguard-rules.pro b/test-util-junit5-android/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/test-util-junit5-android/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/test-util-junit5-android/src/main/AndroidManifest.xml b/test-util-junit5-android/src/main/AndroidManifest.xml new file mode 100644 index 0000000..80e5dbb --- /dev/null +++ b/test-util-junit5-android/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/test/java/org/fnives/test/showcase/testutils/InstantExecutorExtension.kt b/test-util-junit5-android/src/main/java/org/fnives/test/showcase/android/testutil/InstantExecutorExtension.kt similarity index 91% rename from app/src/test/java/org/fnives/test/showcase/testutils/InstantExecutorExtension.kt rename to test-util-junit5-android/src/main/java/org/fnives/test/showcase/android/testutil/InstantExecutorExtension.kt index ca9d988..a3b109e 100644 --- a/app/src/test/java/org/fnives/test/showcase/testutils/InstantExecutorExtension.kt +++ b/test-util-junit5-android/src/main/java/org/fnives/test/showcase/android/testutil/InstantExecutorExtension.kt @@ -1,5 +1,6 @@ -package org.fnives.test.showcase.testutils +package org.fnives.test.showcase.android.testutil +import android.annotation.SuppressLint import androidx.arch.core.executor.ArchTaskExecutor import androidx.arch.core.executor.TaskExecutor import org.junit.jupiter.api.extension.AfterEachCallback @@ -14,6 +15,7 @@ import org.junit.jupiter.api.extension.ExtensionContext * A JUnit5 Extensions that swaps the background executor used by the Architecture Components with a different one which executes each task synchronously. * You can use this extension for your host side tests that use Architecture Components. */ +@SuppressLint("RestrictedApi") class InstantExecutorExtension : BeforeEachCallback, AfterEachCallback { override fun beforeEach(context: ExtensionContext?) {