你如何单元测试一个TCP服务器?它甚至值得吗? [英] How do you unit-test a TCP Server? Is it even worth it?

查看:426
本文介绍了你如何单元测试一个TCP服务器?它甚至值得吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个小的TCP服务器,这将处理一些TCP数据包,并根据请求的行为不同。

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 hard to write, is it even worth the effort?

推荐答案

做的第一件事情就是从TCP数据包的传入分离的行为(S)。摘要变成一只调度表或其他类似的东西。

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.

然后编写单元测试的每个独立的他们是如何调用的行为。您可以测试最终的TCP - >行为层测试工具编写或借阅。这层应该几乎微不足道,如果code正确因素。

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.

这篇关于你如何单元测试一个TCP服务器?它甚至值得吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆