this post was submitted on 20 Jun 2023
8 points (90.0% liked)

Golang

313 readers
3 users here now

This is a community dedicated to the go programming language.

Useful Links:

Rules:

founded 1 year ago
MODERATORS
 

Always interesting to hear different points of view on this subject. Personally I think mocks make sense to capture complex sets of interactions or otherwise difficult to reach error conditions, so I don't think it's a do or do-not kind of thing.

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 3 points 1 year ago* (last edited 1 year ago)

Mock is a necessary thing, but too much mocking is a bad thing.

imo, if your application is layered, then implementing a shallow integration testing and mock out external dependencies and input work better. More mocks make tests less reliable.

I aggree with

Alternative: Don’t unit test calls to complex dependencies. Write integration and behavioral tests for multiple components

One reason we don’t use complex dependencies (even from other packages in the same codebase) is to avoid testing the code of the dependencies. That shouldn’t be a unit test’s responsibility.

But an integration test does care about the code in other packages. That’s the right place to test complex interactions with dependencies.