Timeline for What is the correct way to unit test methods that mix dependencies and business logic?
Current License: CC BY-SA 4.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Sep 2, 2020 at 18:52 | comment | added | Doc Brown | @StephenVernyi: sometimes. It depends. Use your best judgement. | |
| Sep 2, 2020 at 16:43 | comment | added | Stephen Vernyi | Hm. Re #1, do you find value in class-extraction even if the only use-case is in the service that needs it? In other words, the clarity of extraction it provides is worth it. | |
| Sep 2, 2020 at 15:47 | comment | added | Doc Brown | To the 2nd comment: if you are testing something that has dependencies, but you mock out all dependencies, you are unit testing - that is my understanding of the term. An integration test is a test where you don't replace all of the dependencies by mocks, but use at least one "real" dependency. You are testing if two "real" components work together as intended. You can't do this when all dependencies are mocked out. | |
| Sep 2, 2020 at 15:43 | comment | added | Doc Brown | .. when you start calling a function like ApplyRule from a test, or from somewhere else, and not just internally in the class where it is, you make it harder to change its signature later. That's what "being an implementation detail" really means: the ability of changing signatures or internal structure with the least possible effort, without having to change any external code. | |
| Sep 2, 2020 at 15:41 | comment | added | Doc Brown | 1st comment: when you split up two components into separate classes, you make it more clear in your code that something is not "an implementation detail" and you want it to be unit testable, that's a popular convention, not a law. If you don't like the extra code, you can surely keep the ApplyRule function as an internal function where it is, and use the possibility of testing internals (or make the function public just for testing). Several people don't like that, it is unpopular, but not "forbidden". Regardless of how you do it ... | |
| Sep 2, 2020 at 15:26 | comment | added | Stephen Vernyi | I do understand that the intention of mocking dependencies is to unit test. My confusion is that if you are testing something that has dependencies you are testing an integration of parts, not a unit. | |
| Sep 2, 2020 at 15:15 | comment | added | Stephen Vernyi | Why does a class encapsulating the logic mean it is no longer an impl detail, but a method encapsulating the logic is? Certainly you don't extract every pure method into a class. | |
| Sep 2, 2020 at 13:59 | history | edited | Doc Brown | CC BY-SA 4.0 | added 287 characters in body |
| Sep 2, 2020 at 11:19 | history | edited | Doc Brown | CC BY-SA 4.0 | added 10 characters in body |
| Sep 2, 2020 at 6:26 | history | answered | Doc Brown | CC BY-SA 4.0 |