3 ms·
How do you accomplish that? I often end up in a situation where mocks are needed (like in the article).
by geysersam 5y ago
How do you accomplish that? I often end up in a situation where mocks are needed (like in the article).
- saynay 5y agoOften times, you will have chunks of code that are either creating input for what would go into an interface/mock, or handling the output of it. You could pull those bits, even if they are relatively simple (maybe only a few lines, and only used in that one spot), and extract those out to a pure function to sidestep the mock. Sometimes you can't really avoid it. In those cases, I would judge how much of the effort is testing your code, and how much is testing your ability to write mocks. Unless it is a really important functionality, or something complex enough that it would be easy to get wrong, I wouldn't bother with most tests that need extensive mocking. Instead handle those later with integration / e2e tests.