In C ++ProgramDuring unit testing, we often encounter two problems:
1. It is inconvenient to verify the test results because the test results are inaccessible for protection and private class members.
2. It is difficult to bypass connect, receive, and send to be accessed.
Here we will introduce two methods to solve the problem:
1. compile unit testCodeAdd the unit_test macro (the name can be another one you like) and define private as public, that is:
# Define private public
In this way, you can test the code to any member of the classification class. unit testing is to do a white-box test, which clearly shows the interior.
I used to like the method of user Meta class, but it is better to install and test the code in the code.
2. for I/O problems, you only need to inherit from the tested method, and then re-implement (if it is virtual, it is hidden) the corresponding method, to facilitate verification, this will solve the problem. the decorator mode in the design mode is very suitable here.