Created
July 12, 2019 15:08
-
-
Save melihaksoy/9c0d36feaeb07f7bc4c85c6fca293835 to your computer and use it in GitHub Desktop.
Case
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
abstract class TestBaseViewModel : ViewModel() { | |
abstract suspend fun loadData() | |
init { | |
viewModelScope.launch { | |
loadData() | |
} | |
} | |
} | |
class TestViewModel : TestBaseViewModel() { | |
override suspend fun loadData() { | |
println("Boop") | |
} | |
} | |
class BaseTest { | |
@ExperimentalCoroutinesApi | |
private val dispatcher = TestCoroutineDispatcher() | |
@BeforeEach | |
@ExperimentalCoroutinesApi | |
fun setUp() { | |
Dispatchers.setMain(dispatcher) | |
} | |
@AfterEach | |
@ExperimentalCoroutinesApi | |
fun tearDown() { | |
Dispatchers.resetMain() | |
dispatcher.cleanupTestCoroutines() | |
} | |
@Test | |
fun `init should invoke loadData`() { | |
val vm = spyk(TestViewModel()) | |
coVerify(exactly = 1) { | |
vm.loadData() | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment