The unit test cunit of C + + in Linux

Source: Internet
Author: User

When you do a background service, you often debug with debug, but with more before the project is compiled, if you want to test the functionality of a business logic or base library, you can use the Cunit tool for processing.

I. Cunit overview
Cunit is a system that uses the C language to write open-source white-box test case tools to manage and run unit tests. Cunit is connected to the user's test code as a static library.
Cunit uses a simple framework to build a test structure and provides a set of assertion functions for testing common data types. In addition, many different interfaces are provided for running tests and generating reports.
Includes an automated test interface for code-controlled tests and build reports, while the interactive interface is the ability for users to run tests and view results on the fly.
Two. Composition and structure of cunit
1.cunit.h assert macros used in user tests and include other frame header files
2.CUnit structure
Cunit is a platform-independent test framework, and the core framework is the management services that provide basic test registers, test packages, and test cases.
Test the Registration Book
|
-------------------------
| |
Test Package ' 1 ' Test package ' 2 '
| |
------------             --------------
|           |              | |
Test case ' 11 ' test case ' 12 '
Three. Cunit General usage
A typical use order for the Cunit framework is:
1. Write the function for the test (write the Init/cleanup function of the test package if necessary)
2. Initialize test register--cu_initialize_registry ()
3. Add test package to test registration-cu_add_suite ();
4. Add test case to test Package--cu_add_test ();
5. Run the test with the appropriate interface function, for example: Cu_console_run_tests ()
6. Clean up the test register cu_cleanup_registry ();



The unit test cunit of C + + in Linux

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.