Kurt Renzo Acosta
04/12/2020, 4:36 AMsaket
04/12/2020, 7:06 AMKurt Renzo Acosta
04/12/2020, 7:15 AMFakeClassForCase1
, FakeClassForCase2
, and so on or am I missing something in particular?Kurt Renzo Acosta
04/12/2020, 7:27 AMopen
or create an interface for each of them.Arkadii Ivanov
04/12/2020, 8:58 AMArkadii Ivanov
04/12/2020, 9:00 AMArkadii Ivanov
04/12/2020, 9:05 AMKurt Renzo Acosta
04/12/2020, 9:08 AMclass MyViewModel(val useCase: UseCase)
class UseCase(val repository: Repository)
interface Repository
class RepositoryImpl(
val localSource: LocalSource,
val remoteSource: RemoteSource
)
With mocks, I can test MyViewModel
with a
// Setup
val useCase = mockk()
val viewModel = MyViewModel(useCase)
// Stub
coEvery { useCase() } returns ...
// Then do whatever assertion I need
I understand creating fakes for the Repository
and just use a Map
for caching or whatever but when it comes to MyViewModel
and UseCase
seems like I'd need to create an interface for each use case or mark each and every one of them as open
so I can create fake test implementations.Arkadii Ivanov
04/12/2020, 9:10 AMKurt Renzo Acosta
04/12/2020, 9:14 AMKurt Renzo Acosta
04/12/2020, 9:15 AMArkadii Ivanov
04/12/2020, 9:16 AMArkadii Ivanov
04/12/2020, 9:18 AMArkadii Ivanov
04/12/2020, 9:20 AMKurt Renzo Acosta
04/12/2020, 9:21 AMval fakeRepo = FakeRepo()
val useCase = UseCase(fakeRepo)
val viewModel = MyViewModel(useCase)
Then perform tests against it but it seems like I coupled the view model and use case and it becomes an integration test rather than a unit test. Right now, I can't see the benefit of making fakes for use cases.Kurt Renzo Acosta
04/12/2020, 9:25 AMopen class
instead just so I skip the interfaces. Not sure if it's a good idea though. Thanks for your inputs! It's very much appreciated!curioustechizen
04/12/2020, 7:43 PMall-open
curioustechizen
04/12/2020, 7:46 PM