Cicero
01/16/2022, 5:20 PMHey Cicero,
Using interface is a matter of Clean Code Architecture, so yes we are using interfaces with UseCases. Please whenever you need to add a new one make sure that you do an interface for.
This project is intended to be big and continues project, so if we are going to support Unit test in future then we need to make sure that we can test each part separately.
The ViewModel is the only exception at the moment because Koin does not accept interfaces when we define the ViewModel. If we you know a way then please tell me to add interfaces to ViewModels.
So, I understand why I would use interfaces in repositories, right, mocking and what not, but aren't use cases supposed to represent business rules that will shape the information in your view? And aren't this business rules supposed to be prime to the functionality of your viewmodel?
Also, what about adding interfaces everywhere when no code is tested or "it's going to be teste in the future"?
This kind of discussion eat me inside last year.Javier
01/16/2022, 5:45 PMCicero
01/16/2022, 6:30 PMColton Idle
01/17/2022, 4:43 AMK Merle
01/17/2022, 5:53 AMCicero
01/17/2022, 8:29 AMallan.conda
01/17/2022, 6:50 PMClassUnderTest(UseCase(FakeDataSource))
Is not a "Unit" test. You can check out SO discussions about it and there isn't really a complete agreement between software engineers. Also there was/is the trend of Unit test where all dependencies are mocked (even though mockito explicitly says to not mock everything)
I think the problem is the focus on the labeling of whether it is unit test or not, more than focusing on writing valuable tests.
In your case, I would do what would be consistent with the codebase, achieving consistency on the patterns is more important imo. For suggestions like these, I would be willing to discuss but applying your idea means your project needs a migration plan to apply it consistently throughout your codebase. Otherwise you'll get a mix of approaches and when it turns out your team unanimously decides to mock your use cases to write pure unit tests, your code with no interfaces just gets in the way.
Controversial architecture topics like this will stay a 'matter of preference', because the topic is complex enough that there is no answer yet that the majority of the engineering community agrees on.
In my case I'm on the opposite side of the table, where I'm the one trying to enforce the same idea as you, but others don't like it and try to argue against it. (I want Real UseCase with no interface.)
The real challenge is making everyone follow the same thing even though they don't agree on everything.
Tldr; Disagree and CommitCicero
01/17/2022, 8:39 PMK Merle
01/18/2022, 6:28 AMsingle
class does what it's supposed to do, ensures that in the future, if I change anything in a real code accidentally, tests will tell. Also, it's like documenting your code. That being said, if I write use-case unit tests, I don't care about what repository does in his scope, as long as I can mock or fake data of repository, it's fine.George Theocharis
01/19/2022, 8:17 PMK Merle
01/20/2022, 5:05 AMSorin
01/20/2022, 11:55 AMK Merle
01/20/2022, 12:00 PM