3 ms·
> That's called a Mock and some people hate mocks. Don't worry to much about them. Mocks are perfectly OK. It is like putting a mechanical device in a jig fo
by eitland 3y ago
> That's called a Mock and some people hate mocks.
Don't worry to much about them.
Mocks are perfectly OK.
It is like putting a mechanical device in a jig for a durability test or the exhaust extractors that mechanics use when they run engines inside the workshop.
- bluGill 3y agoMocks are okay, if they are used correctly. Often I see them over constraining code and then you cannot change it. If the code will not change delete the tests at they will never fail.
- eitland 3y ago> If the code will not change delete the tests at they will never fail. Or, unless they are expensive, just keep them. The code doesn't change so they won't break. But for the next maintainer they will tell them a lot. One particularly nice thing about some code I maintained recently was that it allowed me to run through different scenarios in my debugger even during my first days in that code base. Also I don't think I will ever again assume that some code that is in production will never change.
- bluGill 3y agoI generally assume that production code will change in the future. Thus if the tests you write today do not guide those changes to not break other existing functionality since they so constrain your implementation that those tests will need to be deleted then the tests are not valuable. I've seen code where every dependency was mocked and all tests ended up being the implementation calls some function with some arguments. Most of the functions can be called many different ways to get the same answers, but the tests forced a specific number.
- eitland 3y agoIt is easy to do mocks wrong. Here is however an example of how one does it right. Say you have a system that accepts input, does something with it and stores it to some storage. You don't want to touch actual storage in the build pipeline. Then you mock in testing out the storage. Everything can still be tested: - the validation of incoming stuff isn't affected at all - the transformations aren't affected - the only difference is your tests now read the output back from a memory location instead of from a permanent storage somewhere