Cunit-a unit test framework for C

Source: Internet
Author: User

(C) Jiang Wei, 2009

 

Recently, the project team wanted to perform a single test on middleware APIs that had been used for a period of time. After half a day, they did not find a good test method. At the beginning, I plan to manually write some data and perform tests one by one, but the log information is not well organized. Suddenly found the cunit stuff. I studied it.

 

After the success of juunit cppunit, the open source white box testing framework cunit also appeared in the C language environment. Cunit is provided to users in the form of source code under the lgpl protocol. Users can add framework code or directly link the compiled static library during programming. It provides a simple unit test framework and supports a wide range of asserted statements for common data types. The current stable version: CUnit-2.1-0.

 

Because this is based on lgpl, we cannot directly use its source code (or the boss will kill me :)). Therefore, you can only compile the static library for calling (the boss is happy now ). However, the default makefile can only be compiled into a library using GCC in Linux. It is not compatible with the hardware environment of the target machine in the Cross-compilation environment of our project. Fortunately, there are not many cunit source files. manually compile them into library files using the compiler of the target machine. Now it's much better to use it. Add the database directly to the project.

 

The organizational structure of cunit is as follows:

Each cunit instance can have only one registy.

Each registy can register multiple suit instances (the Code seems to be 255, but it is hard to remember ...). By ing suit to a project, it can be a module.

At last, each suit can register multiple manually written cases. That is, the API use case to be tested.

 

 

The following steps are generally taken to register a use case:

1. initialize the framework

2. initialize registy

3. Register suit with registy

4. Register a case with suit

5. Run cunit

6. Clear Resources

 

These registration steps are basically fixed. The cunit contains a complete sample, which is easy to grasp. Then you can use it two more times to get familiar with it.

 

Cunit provides four test modes:

1. Basic

2. Automatic

3. Console

4. cursor

 

The basic mode directly runs the registered use cases one by one and outputs the test results in the standard output.

The automated mode runs the use case once and generates test results in an intuitive XML file format.

Console is a simple option for console interaction mode, such as selecting a test case.

Cursor I have never used this mode. cunit is a dedicated mode in Unix. If it is null, try it.

 

The most single test framework cunit does not directly provide you with a complete test case. Instead, it is automatically called based on a manually written test case. Latency is required for some asynchronous APIs. In general, I think it is more practical for small and medium-sized projects.

 

PS: the XML file generated by automated can be properly displayed only when several DTD and XSL files under the share directory of the source code are used together. I didn't pay attention to this for the first time, and I couldn't see any reports generated...

 

Above

Jiang Wei

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.