Comparison of the C ++ unit test framework (zz)

Source: Internet
Author: User

Address: http://hi.baidu.com/shuiyuan2004/blog/item/7d4b43eccdf5c2d32f2e213f.html

Comparison of C ++ unit test frameworks

Unit testing has now become a standard programming practice, but C ++ lacks Java and.. NET platform language reflection mechanism, so it is impossible to enumerate test methods. You must manually add them, or use some special macros.CodeVery ugly. Java language unit testing is the world of JUnit, C # basically uses nunit, while C ++ is in full bloom, there are many unit testing frameworks, and the cppunit transplanted by JUnit, boost :: test, cpptest, cxxtest, tut, and so on. But the best solution is cxxtest and tut. cxxtest adopts a special method. It uses Perl to analyze the C ++ source file, extract the test method from it, and create testsuite. The syntax is very similar to JUnit. It does not use advanced C ++ features and does not define special macros. No additional code is required. Tut is also a good solution. Using the advanced C ++ template function, it must be supported by a newer compiler, such as vc6 and. NET 2002 is not supported. It must be. NET 2003 or above or Intel C ++ complier 8.1 or above.

1,Tut

The architecture is simple. Adding a new test requires a small amount of work; you do not need to register for the test; portability is good (because it only requires two header files to complete the test); Ease of loading and unloading; interfaces can be provided to expand its output mode.

The biggest advantage: lightweight, easy loading and unloading, and scalable output mode;

Disadvantage: assertion does not seem very good. I only use an ensure () function and do not know whether to support complex tests. The output test results are relatively simple.

2,Boost: Test

The structure framework is complex. It does not take much effort to add new tests. Multiple test methods are provided, and test cases can be registered or not registered. portability is average and loading and unloading is not easy; the ability to control exceptions and crashes is better than that of all other competitors. It has good assertions. It probably supports multiple output modes, but it is not easy to change the output mode. It also supports Test suites.

The biggest advantage is the ability to control abnormal crashes, good assertions, detailed output results, and flexible testing methods;

Disadvantage: The structure framework is complex, and it is difficult to change the output mode and load/unload.

3,Cxxtest

The complexity of the structure framework is between tut and boost: test. Adding a new test workload is very small; you do not need to register test cases; portability is good; loading and unloading is easy; the ability to control exceptions and crashes is also good; good assertions; supports multiple output modes and Test suites.

The biggest advantage: compilation is the test method, and you can double-click the result line to locate the correspondingSource codeIt is quite attractive. It supports multiple outputs and provides more detailed output results. It is easy to write and test;

Disadvantage: You need to use Perl to perform a grammar scan on the test code to generate executable code. You need to use the MAKEFILE file (not required). It is troublesome to prepare.

Related Article

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.