mirror of
https://github.com/hmalik144/EasyCC_Master.git
synced 2025-12-10 03:05:29 +00:00
- Fix failing unit tests
Took 30 minutes
This commit is contained in:
@@ -49,6 +49,9 @@ dependencies {
|
||||
androidTestImplementation 'androidx.test:rules:1.4.0'
|
||||
implementation 'org.jetbrains.kotlin:kotlin-test:1.7.10'
|
||||
|
||||
// Coroutines
|
||||
def coroutines_version = "1.6.2"
|
||||
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version"
|
||||
|
||||
//Retrofit and GSON
|
||||
def retrofit_ver = "2.8.1"
|
||||
|
||||
@@ -6,7 +6,9 @@ import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||
import com.appttude.h_mal.easycc.data.network.response.ResponseObject
|
||||
import com.appttude.h_mal.easycc.data.repository.Repository
|
||||
import com.appttude.h_mal.easycc.helper.CurrencyDataHelper
|
||||
import com.appttude.h_mal.easycc.utils.MainCoroutineRule
|
||||
import com.appttude.h_mal.easycc.utils.observeOnce
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
@@ -23,6 +25,9 @@ class MainViewModelTest {
|
||||
@get:Rule
|
||||
val instantTaskExecutorRule: InstantTaskExecutorRule = InstantTaskExecutorRule()
|
||||
|
||||
@get:Rule
|
||||
var mainCoroutineRule = MainCoroutineRule()
|
||||
|
||||
lateinit var viewModel: MainViewModel
|
||||
|
||||
@Mock
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.appttude.h_mal.easycc.utils
|
||||
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.*
|
||||
import org.junit.rules.TestWatcher
|
||||
import org.junit.runner.Description
|
||||
|
||||
@ExperimentalCoroutinesApi
|
||||
class MainCoroutineRule(private val dispatcher: TestDispatcher = StandardTestDispatcher()) :
|
||||
TestWatcher() {
|
||||
|
||||
override fun starting(description: Description) {
|
||||
super.starting(description)
|
||||
Dispatchers.setMain(dispatcher)
|
||||
}
|
||||
|
||||
override fun finished(description: Description) {
|
||||
super.finished(description)
|
||||
Dispatchers.resetMain()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user