Issue#67 Extract InstantExecutorExtension

This commit is contained in:
Gergely Hegedus 2022-07-12 11:31:06 +03:00
parent 8d60a37b16
commit 3b96a5d9eb
14 changed files with 75 additions and 9 deletions

View file

@ -107,10 +107,11 @@ dependencies {
androidTestImplementation project(':mockserver') androidTestImplementation project(':mockserver')
testImplementation testFixtures(project(':core')) testImplementation testFixtures(project(':core'))
testImplementation project(':test-util-junit5-android')
androidTestImplementation testFixtures(project(':core')) androidTestImplementation testFixtures(project(':core'))
implementation project(':test-util-shared-robolectric') testImplementation project(':test-util-shared-robolectric')
androidTestImplementation project(':test-util-shared-android') androidTestImplementation project(':test-util-shared-android')
implementation project(':test-util-android') testImplementation project(':test-util-android')
androidTestImplementation project(':test-util-android') androidTestImplementation project(':test-util-android')
} }

View file

@ -3,11 +3,11 @@ package org.fnives.test.showcase.ui.auth
import com.jraska.livedata.test import com.jraska.livedata.test
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking 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.core.login.LoginUseCase
import org.fnives.test.showcase.model.auth.LoginCredentials import org.fnives.test.showcase.model.auth.LoginCredentials
import org.fnives.test.showcase.model.auth.LoginStatus import org.fnives.test.showcase.model.auth.LoginStatus
import org.fnives.test.showcase.model.shared.Answer 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.testutils.TestMainDispatcher
import org.fnives.test.showcase.ui.shared.Event import org.fnives.test.showcase.ui.shared.Event
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach

View file

@ -1,8 +1,8 @@
package org.fnives.test.showcase.ui.auth package org.fnives.test.showcase.ui.auth
import kotlinx.coroutines.ExperimentalCoroutinesApi 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.core.login.LoginUseCase
import org.fnives.test.showcase.testutils.InstantExecutorExtension
import org.fnives.test.showcase.testutils.TestMainDispatcher import org.fnives.test.showcase.testutils.TestMainDispatcher
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.DisplayName

View file

@ -4,6 +4,7 @@ import com.jraska.livedata.test
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.runBlocking 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.AddContentToFavouriteUseCase
import org.fnives.test.showcase.core.content.FetchContentUseCase import org.fnives.test.showcase.core.content.FetchContentUseCase
import org.fnives.test.showcase.core.content.GetAllContentUseCase 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.FavouriteContent
import org.fnives.test.showcase.model.content.ImageUrl import org.fnives.test.showcase.model.content.ImageUrl
import org.fnives.test.showcase.model.shared.Resource import org.fnives.test.showcase.model.shared.Resource
import org.fnives.test.showcase.testutils.InstantExecutorExtension
import org.fnives.test.showcase.testutils.TestMainDispatcher import org.fnives.test.showcase.testutils.TestMainDispatcher
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.DisplayName

View file

@ -2,8 +2,8 @@ package org.fnives.test.showcase.ui.splash
import com.jraska.livedata.test import com.jraska.livedata.test
import kotlinx.coroutines.ExperimentalCoroutinesApi 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.core.login.IsUserLoggedInUseCase
import org.fnives.test.showcase.testutils.InstantExecutorExtension
import org.fnives.test.showcase.testutils.TestMainDispatcher import org.fnives.test.showcase.testutils.TestMainDispatcher
import org.fnives.test.showcase.ui.shared.Event import org.fnives.test.showcase.ui.shared.Event
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach

View file

@ -26,7 +26,7 @@ project.ext {
arch_core_version = "2.1.0" arch_core_version = "2.1.0"
testing_livedata_version = "1.2.0" testing_livedata_version = "1.2.0"
testing_kotlin_mockito_version = "4.0.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_json_assert_version = "1.5.0"
testing_junit4_version = "4.12" testing_junit4_version = "4.12"
testing_robolectric_version = "4.7" testing_robolectric_version = "4.7"

View file

@ -27,6 +27,6 @@ dependencies {
applyNetworkTestDependenciesTo(this) applyNetworkTestDependenciesTo(this)
testFixturesApi project(':mockserver') 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" testFixturesApi "io.insert-koin:koin-test-junit5:$koin_version"
} }

View file

@ -7,3 +7,4 @@ include ':app'
include ':test-util-shared-android' include ':test-util-shared-android'
include ':test-util-shared-robolectric' include ':test-util-shared-robolectric'
include ':test-util-android' include ':test-util-android'
include ':test-util-junit5-android'

1
test-util-junit5-android/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/build

View file

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

View file

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

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.fnives.test.showcase.android.testutil">
</manifest>

View file

@ -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.ArchTaskExecutor
import androidx.arch.core.executor.TaskExecutor import androidx.arch.core.executor.TaskExecutor
import org.junit.jupiter.api.extension.AfterEachCallback 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. * 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. * You can use this extension for your host side tests that use Architecture Components.
*/ */
@SuppressLint("RestrictedApi")
class InstantExecutorExtension : BeforeEachCallback, AfterEachCallback { class InstantExecutorExtension : BeforeEachCallback, AfterEachCallback {
override fun beforeEach(context: ExtensionContext?) { override fun beforeEach(context: ExtensionContext?) {