It is increasingly found that unit testing is important when it comes to actually doing projects, or bugs continue to be a waste of time and, more importantly, a great inconvenience to other people.
It feels like the unit tests offered by boost are good and relatively simple.
If you are writing multiple test cases, you can do the following:
File1.cpp #include <boost/test/unit_test.cpp> .... Boost_auto_test_suite (File1_test_suite) boost_auto_test_case (freader_test) {...} Boost_auto_test_case (freader_test) {...} Boost_auto_test_suite_end ()-End of file 1-file2.cpp #include <boost/test/unit_test.cpp> .... Boost_auto_test_suite (File2_test_suite) boost_auto_test_case (test1) {...} Boost_auto_test_case (test2) {...} Boost_auto_test_suite_end ()-End of file 2-test_main.cpp #define Boost_test_module master_test_suite #include <boost /test/included/unit_test.hpp>-End of Test_main.cpp-
Note that the include for the main function differs from the test_suit include file.
Additionally, if you do not use BOOST lib, you must add predefined macros Boost_test_no_lib or boost_all_no_lib, or you may find no Lib error.
Or
#include <boost/test/included/unit_test.hpp> using namespace boost::unit_test; void Free_test_function () {...} test_suite* init_unit_test_suite (int argc, char* argv[]) {Framework::master_test_suit E (). Add (Boost_test_case (&free_test_function)); return 0; }
It's more convenient to test for memory leaks or something like this.
However, if there is a memory leak, although there are some means to track the memory leak statement line number, but extremely inconvenient. I now also use Purifyplus, can be very convenient to locate the statement, but the program run up that is quite slow.