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.

  • @learningduck@programming.dev
    link
    fedilink
    English
    1
    edit-2
    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.