How to deal with interface overuse in TDD?

前端 未结 4 1171
不思量自难忘°
不思量自难忘° 2021-02-01 17:30

I\'ve noticed that when I\'m doing TDD it often leads to a very large amount of interfaces. For classes that have dependencies, they are injected through the constructor in the

4条回答
  •  礼貌的吻别
    2021-02-01 18:01

    That's the drawback of mock based testing approaches. This is as much a test boundary discussion as it is about mocking. By having a 1:1 ratio of test cases to domain classes your test boundary is very small. A result of a small test boundary is a proliferation of interfaces and tests that depend on them. Refactoring becomes more difficult due to the number of interactions you are mocking and stubbing out. By testing clusters of classes with a single test, refactoring becomes easier and you use fewer interfaces. Beware, however that you can test too many classes at once. The more complexity your classes have, the more code paths you need to test. This can lead to a combinatorial explosion and you can't possibly test them all. Listen to the code and tests, they're telling you something about your code. If you see the complexity increasing, it's probably a good time to introduce a new Test Case and Interface/Implementation and mock it out in your original.

提交回复
热议问题