Network code has proved that it is difficult to perform a thorough test, because the test component does not depend on other servers and works as an independent process for the best time. In this article, Nelson Minar describes two methods for unit test network code. First, he suggested that you should be logically independent from the network when designing network code. Next, he suggested using the Java protocol processor class to simulate Network Connections instead of using the actual network. With these principles, you can easily generate network testing software.
Testing network code is very difficult. ExcellentUnit TestThe component runs very quickly, so that developers can perform tests after each compilation. Of course, the test stream must also run stably so that they can continuously capture any errors in the code. However, practice has proved that it is difficult to quickly and stably test network code (for example, Code read from a URL. Moreover, if the test component performs network calling, the test will become very slow and unstable because of the network dependency and other servers.
Read: http://www.javah.net/wangluobiancheng/20070611/2618.html