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