Issue#67 Extract InstantExecutorExtension
This commit is contained in:
parent
8d60a37b16
commit
3b96a5d9eb
14 changed files with 75 additions and 9 deletions
|
|
@ -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')
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
package org.fnives.test.showcase.testutils
|
||||
|
||||
import androidx.arch.core.executor.ArchTaskExecutor
|
||||
import androidx.arch.core.executor.TaskExecutor
|
||||
import org.junit.jupiter.api.extension.AfterEachCallback
|
||||
import org.junit.jupiter.api.extension.BeforeEachCallback
|
||||
import org.junit.jupiter.api.extension.ExtensionContext
|
||||
|
||||
/**
|
||||
* Junit5 Version of InstantTaskExecutorRule from Junit4
|
||||
*
|
||||
* reference: https://developer.android.com/reference/androidx/arch/core/executor/testing/InstantTaskExecutorRule
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
class InstantExecutorExtension : BeforeEachCallback, AfterEachCallback {
|
||||
|
||||
override fun beforeEach(context: ExtensionContext?) {
|
||||
ArchTaskExecutor.getInstance()
|
||||
.setDelegate(object : TaskExecutor() {
|
||||
override fun executeOnDiskIO(runnable: Runnable) = runnable.run()
|
||||
|
||||
override fun postToMainThread(runnable: Runnable) = runnable.run()
|
||||
|
||||
override fun isMainThread(): Boolean = true
|
||||
})
|
||||
}
|
||||
|
||||
override fun afterEach(context: ExtensionContext?) {
|
||||
ArchTaskExecutor.getInstance().setDelegate(null)
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue