Last active
February 9, 2021 12:07
-
-
Save prokash-sarkar/9b86951e7bbe4b2d6c04165357c4f757 to your computer and use it in GitHub Desktop.
This Gist is a part of the Article: https://prokash-sarkar.medium.com/unit-testing-with-dagger-2-brewing-a-potion-with-fakes-mocks-and-custom-rules-in-android-7f0ab7b22cb
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
class DefaultDataRepositoryTest { | |
private val remoteDataSource: DataSource = mockk() | |
private lateinit var dataRepository: DefaultDataRepository | |
@Before | |
fun setup() { | |
dataRepository = DefaultDataRepository(remoteDataSource) | |
} | |
@ExperimentalCoroutinesApi | |
@Test | |
fun getSearchResponse_testMethodCall() = runBlockingTest { | |
val repoList = mutableListOf<Repo>() | |
val repo = Repo(1, "test_repo", "test_name", "test_desc", "test_url", 1, 1, "en") | |
repoList.add(repo) | |
val response = RepoSearchResponse(1, repoList) | |
coEvery { remoteDataSource.getSearchResponse("android", 1, 1) } returns response | |
dataRepository.getSearchResponse("android", 1, 1) | |
coVerify { remoteDataSource.getSearchResponse("android", 1, 1) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment