Summarize the unit test __c++ under C + +

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.