Earlier quoted context omitted.
Why do fakes need tests, but mocks don't? In one case you create the class on your own, in the other case the mocking framework does that for you on the fly. With both approaches you can do very basic or very complicated things. Or do you have a rule in your company that every class needs a test? Maybe this rule is the problem.
> Why do fakes need tests, but mocks don't? because no new class or method is created with mocks, it's merely declarative, no new logic is created than needs to be tested. Fakes very much have logic since they are implementations of classes. > Or do you have a rule in your company that every class needs a test? Maybe this rule is the problem. No Fakes are, not the fact that every unit should be tested. Fakes are very…
Prefer Fakes over Mocks
111–120 of 125 posts
Re: Prefer Fakes over Mocks
#112Re: Prefer Fakes over Mocks
#113I watch more people overcomplicate their lives when it comes to unit testing. The problem discussed in this article is not one of mock vs. fake its actually about how this individual chose to engineer their application. First I'll introduce some axioms... 1. Mixing unit and integration testing is not ideal. If you are doing unit testing focus on verifying the code paths within the unit. When considering the collabora…
Re: Prefer Fakes over Mocks
#114Not particularly convincing. Mocks work well because you can quickly define them in a given unit test and forget about it. I can see fakes being useful in certain cases, but only just in certain cases. Could be my inexperience with C#, but it didn't do justice describing the point in code samples.
Re: Prefer Fakes over Mocks
#115Earlier quoted context omitted.
Mocks for your own code, fakes for external dependencies but in both cases only where you can’t rework your most of your code to consume the outputs of dependencies instead of soliciting them. Fixtures trump mocks and fakes. Having multiple tests fail for the same reason is a waste of effort, either now or in the future (when new features are added or the constraints otherwise change). Sometimes you have to depend on…
Why would you mock your own code, when you have your own real code right there?
Re: Prefer Fakes over Mocks
#116Earlier quoted context omitted.
Mocks for your own code, fakes for external dependencies but in both cases only where you can’t rework your most of your code to consume the outputs of dependencies instead of soliciting them. Fixtures trump mocks and fakes. Having multiple tests fail for the same reason is a waste of effort, either now or in the future (when new features are added or the constraints otherwise change). Sometimes you have to depend on…
Why would you mock your own code, when you have your own real code right there?
Re: Prefer Fakes over Mocks
#117Earlier quoted context omitted.
>> .. fully functional fake of the original class. So they are coupled to the implementation of the object in any case!
Quoting the article: > It may also appear that the details we have to take into account here are not that different from the implementation-aware assumptions we were making when using mocks, as neither are actually governed by the interface of the component. However, the major distinction is that the coupling we institute here is between the test double and the real implementation of the component, rather than betwee…
Re: Prefer Fakes over Mocks
#118Earlier quoted context omitted.
The benefits you describe for OOP can be achieved in FP through function composition. DI doesn't have to mean you set up a container, you know. > I know that something akin to this is theoretically possible in functional languages, but I've found that in practice it's more difficult. Could you explain what you think is hard about it?
Function composition doesn't spring to mind when I think fakes/mocks/testing. As a long-time functional programmer, the things I'd reach for are: Higher-order functions: rather than taking a 'service object' as an argument, and calling one or two of its methods, we can accept the methods/functions we need as arguments. Tests can pass in their own functions, which looks a lot like mocking but doesn't need any tricks o…
Re: Prefer Fakes over Mocks
#119Earlier quoted context omitted.
> if you can modify the system to make testing against it easier, that's even better. What do you mean here? Changing your testing system, or changing the real system?
Changing the real system to add the hooks you need. Complexity often exists around waiting for events to happen (the real system doesn't need notifications, but you don't want your tests to run forever when they're failing), clocks (time.Now() is difficult to test), things like that.
This is why I'd want test to just have a lot more 'leeway' than normal code. Essentially I want heavy hooking, introspection and reflexivity but only for tests.
Re: Prefer Fakes over Mocks
#120Earlier quoted context omitted.
> Because they don't just implement a part of the interface (just one store method, or just one of two load methods). They try to create a fully functional fake of the original class. So shouldn't fakes have their own tests as well? Mocks don't need tests (at least in C# with a framework) because no new class is ever written. Anyway most of these issues are inherently linked to the nature of OOP and are a direct trad…
On the best scenario, your fakes just replace some standard components your have on production with other standard components, and keep everything else equal. On those cases, no they don't need tests. But when you are doing something weirder, they pretty much do. On the best scenario, your mocks are just data that doesn't have timing characteristics, don't react to the system being tested, and are short enough to not…
There is no need for Mocks or Fakes with pure functions.