Created
March 21, 2021 15:35
-
-
Save Abdelsattar/aeb2630df893febebd135b6cc47cc6a9 to your computer and use it in GitHub Desktop.
Fix problem live data with Junit 5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| 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) | |
| } | |
| } | |
| // based on this answer https://stackoverflow.com/a/57843898/3553843 | |
| // and then add like this | |
| @ExtendWith(InstantExecutorExtension::class) | |
| class ContentViewModelTest { | |
| } | |
| that works for me |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment