How do you unit-test a TCP Server? Is it even worth it?

后端 未结 8 1218
一整个雨季
一整个雨季 2021-02-05 10:03

I\'m developing a small TCP server, which will process some TCP packets and behave differently based on the request.

How can I write unit test for this? If it\'s really

8条回答
  •  粉色の甜心
    2021-02-05 10:54

    The first thing to do is to separate the behavior(s) from the TCP packets that are incoming. Abstract that into a dispatch table or other such thing.

    Then write unit tests for each of the behaviors independent of how they were invoked. You can test the final TCP -> behavior layer with a test tool you write or borrow. That layer should be almost trivial if the code is factored properly.

提交回复
热议问题