开发者

Is Mockery a TDD anti-pattern? [closed]

开发者 https://www.devze.com 2023-03-28 14:30 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that t开发者_StackOverflow社区his question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

I read this answer which tells Mockery is an anti-pattern of TDD. But wait! We have to mock/stub all dependencies to write a unit-test. In other case it would be an integration test.


Overusing mocks can be an antipattern, not mocking itself. It's true that you need to mock/stub your dependencies, but when your class has too many dependencies, it can take more time and effort to mock and wire up everything correctly than to write the class itself. And the mocking definitions are very fragile and easy to break, what is somehow against TDD rules.

Too many dependencies means either that your class is some kind of god object that needs to be refactored or is some kind of top-level coordinator that do not have any special logic on its own (like only sequence of dependency calls), in which case I would say it is not really needed to unit test it, when all its components are unit tested well (integration tests can cover this nicely, unit test will be mocking hell without any real value).

0

精彩评论

暂无评论...
验证码 换一张
取 消