Introduction to Unit Testing with CUnit

上一篇 / 下一篇  2008-09-19 12:11:31 / 个人分类:CUnit Progammers Guide

1. Introduction to Unit Testing with CUnit
介绍单元测试和CUnit
1.1. Descrīption
描述
CUnit is a system for writing, administering, and running unit tests in C.
CUnit 可以在C的项目上编写,管理,运行单元测试,
It is built as a static library which is linked with the user's testing code.
它建立一个静态库和用户的代码链接在一起
CUnit uses a simple framework for building test structures, and provides a rich set of assertions for testing common data types.
CUnit 用了一个简单的框架来建立测试结构, 并且为常用的数据类型提供了丰富的断言语句支持。
In addition, several different interfaces are provided for running tests and reporting results.
此外.可以为测试运行和测试报告提供不同的接口
These include automated interfaces for code-controlled testing and reporting, as well as interactive interfaces allowing the user to run tests and view results dynamically.
还包括控制代码的测试和报告的自动化界面,以及交互式界面也考虑到用户测试的运行和动态结果视图
The data types and functions useful to the typical user are declared in the following header files:
典型的用户用到数据类型和功能会使用以下头文件:
Header File     Descrīption
#include <CUnit/CUnit.h>     ASSERT macros for use in test cases, and includes other framework headers.
                ASSERT 宏用于测试用例也包括其他框架头文件
#include <CUnit/CUError.h>     Error handing functions and data types. Included automatically by CUnit.h.
                
#include <CUnit/TestDB.h>     Data type definitions and manipulation functions for the test registry, suites, and tests. Included automatically by CUnit.h.
#include <CUnit/TestRun.h>     Data type definitions and functions for running tests and retrieving results. Included automatically by CUnit.h.
#include <CUnit/Automated.h>     Automated interface with xml output.
                自动化界面与xml 输出
#include <CUnit/Basic.h>     Basic interface with non-interactive output to stdout.
                基础界面与非交互式标准输出
#include <CUnit/Console.h>     Interactive console interface.
                交互式控制台界面
#include <CUnit/CUCurses.h>     Interactive console interface (*nix).
                交互式控制台界面(unix)
#include <CUnit/Win.h>     Windows interface (not yet implemented).
                windows界面(没有实现)

1.2. Structure
结构
CUnit is a combination of a platform-independent framework with various user interfaces.
CUnit 是一个结合各种用户界面的独立平台框架
The core framework provides basic support for managing a test registry, suites, and test cases.
该框架核心提供了基本的支持,管理一个测试的注册表,组件,测试用例.
The user interfaces facilitate interaction with the framework to run tests and view results.
用户界面容易在交互式作用的框架内进行测试和查看结果
CUnit is organized like a conventional unit testing framework:
CUnit 的组织像传统的单元测试框架

                      Test Registry
                            |
             ------------------------------
             |                            |
          Suite '1'      . . . .       Suite 'N'
             |                            |
       ---------------             ---------------
       |             |             |             |
    Test '11' ... Test '1M'     Test 'N1' ... Test 'NM'

Individual test cases are packaged into suites, which are registered with the active test registry.
个别几个测试用例封装到suites里面,该组件被注册,并且激活该注册表
Suites can have setup and teardown functions which are automatically called before and after running the suite's tests.
在运行Suite测试前后,suite能够自动调用装载和卸载的功能,
All suites/tests in the registry may be run using a single function call, or selected suites or tests can be run.
所有的suites/测试都有可能执行一个简单的功能或者选择一个suites 或者执行一个测试用例调用注册表

1.3. General Usage
A typical sequence of steps for using the CUnit framework is:
使用CUnit的一个典型步骤是:
   1. Write functions for tests (and suite init/cleanup if necessary).
     编写一个测试函数 (suite 初始化和销毁)
   2. Initialize the test registry - CU_initialize_registry()
    初始化测试注册表
   3. Add suites to the test registry - CU_add_suite()
    添加suites 到注册表
   4. Add tests to the suites - CU_add_test()
    添加测试用例到注册表
   5. Run tests using an appropriate interface, e.g. CU_console_run_tests
    运行测试用例使用一个合适的界面
   6. Cleanup the test registry - CU_cleanup_registry
    释放测试注册表
1.4. Changes to the CUnit API in Version 2
     转到第2版,CUnit API
All public names in CUnit are now prefixed with 'CU_'.
在CUnit中,现在所有公共的名字都要加上前缀"CU_"
This helps minimize clashes with names in user code.
在用户代码中,有助于减少名字相同
Note that earlier versions of CUnit used different names without this prefix.
注意在早期版本CUnit使用不同的名字,没有前缀
The older API names are deprecated but still supported.
老的API,仍然支持
To use the older names, user code must now be compiled with USE_DEPRECATED_CUNIT_NAMES defined.
使用旧的名称,用户必须在编译代码的是定义 USE_DEPRECATED_CUNIT_NAMES
The deprecated API functions are described in the appropriate sections of the documentation.
在部分文档中描述废弃的API
相关阅读:

TAG: CUnit

 

评分:0

我来说两句

Open Toolbar