"Article Summary "
In the Software development phase, Unit testing is an important way to ensure the quality of your code. Therefore, mastering the basic unit testing method is a basic requirement for a software developer.
Based on the author's actual project experience, this paper introduces a kind of unit test method which is used much more.
I. Overview of software modules
In the actual software system, the relationship between the various modules can be described by the intricacies. The software modules can be divided into the following four classes, depending on the message interaction between the modules.
First Category: Standalone modules. That is, the module does not receive messages sent by other modules, and does not send messages to other modules.
The second type: passive one-way message module. That is, the module only receives messages from other modules and does not send messages to other modules.
The third type: The active one-way message module. That is, the module only sends messages to other modules, not messages sent by other modules.
Class fourth: Two-way message module. That is, the module must receive messages from other modules, but also send messages to other modules.
According to the different types of software modules, different unit testing methods should be used to "adapt to local conditions". This paper introduces the unit test method of class fourth software module.
Two, two-way message module features
Generally speaking, the main features of class fourth (Bidirectional message module) are as follows:
First, we strictly follow the agreed protocol with other modules for message interaction. The successful execution of the program can be seen through the relevant protocol fields.
Second, you have to agree on a good message event number and message sequence number. The purpose of this is to allow the module to process message processing in a methodical manner.
Thirdly, the requirements for the efficiency of the program execution of the module are higher. If you receive a message after half a day to give a reply, then almost no module can accept such "inefficiency."
Third, unit test of two-way message module
Based on the characteristics of the two-way message module, we specialize in developing a software module (the test program) for sending messages to the module. To ensure that the number of messages sent is controllable, we put the test case in the configuration file, which is read, parsed, and sent by the test program. The detailed procedure for unit testing of two-way message modules is shown in 1:
Figure 1 Detailed procedure for unit testing of a two-way message module
The description is as follows:
First, when setting up test cases, try to cover all the processes that you want to test the code. That is, to make all the program branches run over. In addition, both normal and abnormal test cases are set.
Second, if you encounter an exception to a log that is not sending messages or programs, you should modify the code or configuration in question immediately and then rerun the program. At the beginning of the test, you can send only one message at a time to see if the whole process is correct. You can then consider sending multiple messages each time (defining the message event number and message sequence number) and testing the processing performance of the module under test.
Thirdly, when the software needs more, we can do unit test every one or several requirements, and then continue to complete the new requirement after the developed function is confirmed.
Iv. Summary
Unit testing and integration testing of developed modules is a must for every developer before submitting a software release. Only if the self-test is sufficient, the quality of the software version can be improved. If the problem of the program is left behind on-site commercial, then the cost or loss caused by the modification will be greatly increased. Therefore, each developer should develop a good habit of unit testing the program.
This paper introduces the specific process of unit testing for two-way message module, and provides a useful reference for the successful development of the related software.
(I Weibo: Http://weibo.com/zhouzxi?topnav=1&wvr=5, No.: 245924426, welcome attention!) )
A method for unit testing of software modules