TDD and Mocking out TcpClient

前端 未结 3 2061
清歌不尽
清歌不尽 2020-12-14 12:14

How do people approach mocking out TcpClient (or things like TcpClient)?

I have a service that takes in a TcpClient. Should I wrap that in something else more mocka

3条回答
  •  渐次进展
    2020-12-14 12:48

    Using the Adapter pattern is most definitely the standard TDD approach to the problem. You could, however, also just create the other end of the TCP connection and have your test harness drive that.

    IMO the widespread use of adapter class obfuscates the most important parts of a design, and also tends to remove a lot of stuff from being tested that really ought to be tested in context. So the alternative is to build up your testing scaffolding to include more of the system under test. If you are building your tests from the ground up, you'll still achieve the ability to isolate the cause of a failure to a given class or function, it just won't be in isolation...

提交回复
热议问题