Cunit简介
来源:互联网 发布:矩阵a与b相似 编辑:程序博客网 时间:2024/04/26 06:49
本博客(http://blog.csdn.net/livelylittlefish )贴出作者(三二一@小鱼)相关研究、学习内容所做的笔记,欢迎广大朋友指正!
Content
1. What is CUnit?
2. What are the interfaces?
3. How to use CUnit framework?
4. An example
Appendix installation of CUnit
(1) install curses/ncurses
(2) install CUnit
1. What is CUnit?
(1) CUnit is a system for writing, administering, and running unit tests in C.
(2) It is built as a static library which is linked with the user's testing code.
(3) CUnit uses a simple framework for building test structures, and provides a rich set of assertions for testing common data types.
2. What are the interfaces?
There are some kinds of interfaces of CUnit for running tests and reporting results.
(1) Automated interface with xml output
(2) Basic interface with non-interactive output to stdout
(3) Interactive console interface
(4) Interactive console interface (*nix)
(5) Windows interface (not yet implemented)
3. How to use CUnit framework?
The following is the typical of steps for using CUnit framework.
(1) Write functions for tests (and suite init/cleanup if necessary)
(2) Initialize the test registry, by calling CU_initialize_registry()
(3) Add suites to the test registry, by calling CU_add_suite()
(4) Add tests to the suites, by calling CU_add_test()
(5) Run tests using an appropriate interface, e.g. by calling CU_console_run_tests()
(6) Cleanup the test registry, by calling CU_cleanup_registry()
4. test, suite, registry
Registry由1个或多个suite构成;
suite由1个或多个test case构成;
suite可以有setup/teardown方法,并在执行suite中的tests前/后被自动调用;
所有的suites/tests可由一个相应函数触发执行,例如,CU_console_run_tests(),也可以选择某个/些suites/tests执行;
5. An example
the platform can be cgywin (win32) or Linux. 该例子就是其官方文档中的例子,http://cunit.sourceforge.net/example.html,代码如下。
makefile文件内容
test: test.o
gcc -g -o $@ $^ -lcunit -lcurses
test.o: test.c
gcc -g -c $^
clean:
rm test *.o
注:使用CUnit框架的单元测试,需要curses库的支持。
编译运行如下,适合于Linux、Cygwin和Win32平台。
# make
gcc -c -g test.c
gcc -g -o test test.o -lcunit
# ./test
CUnit - A unit testing framework for C - Version 2.1-2
http://cunit.sourceforge.net/
Suite: Suite_1
Test: test of fprintf() ...passed
Test: test of fread() ...passed
Run Summary: Type Total Ran Passed Failed Inactive
suites 1 1 n/a 0 0
tests 2 2 2 0 0
asserts 5 5 5 0 n/a
Elapsed time = 0.000 seconds
Detailed information and programmers guide, please refer the reference.
Reference
http://cunit.sourceforge.net
http://cunit.sourceforge.net/doc/index.html
Appendix: installation of CUnit
(1) install curses/ncurses
Since CUnit will depend curses/ncurses, then, before install CUnit, curses/ncurses must be installed. Otherwise, there will be errors during compiling CUnit.
$ cd /usr/src
$ wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz
$ tar -zxvf ncurses-5.9.tar.gz
$ ./configure
$ make
$ make install
The following links will show you the detail of curses/ncurses.
http://www.gnu.org/software/ncurses
http://en.wikipedia.org/wiki/Ncurses
http://en.wikipedia.org/wiki/Curses_%28programming_library%29
http://blog.csdn.net/dai_weitao/archive/2007/07/26/1708712.aspx
(2) install CUnit
CUnit must be installed in cygwin, since some header files will be used in the unit test.
# wget http://sourceforge.net/projects/cunit/files/CUnit/2.1-2/CUnit-2.1-2-src.tar.bz2
# bzip2 -d CUnit-2.1-2-src.tar.bz2
# tar -xvf CUnit-2.1-2-src.tar
# cd CUnit-2.1-2
# ./configure -h //查看配置帮助
//enable debugging, and compile CUnit example programs
# ./configure --enable-debug=yes --enable-curses=yes --enable-examples=yes
Then, the header files and library of CUnit will be installed in cygwin. And you can run the examples for some basic concept.
The following links will show you the detailed information.
http://cunit.sourceforge.net
http://cunit.sourceforge.net/doc/index.html
http://cunit.sourceforge.net/doxdocs/index.html
- Cunit简介
- 单元测试工具 CUnit 简介
- 单元测试工具 CUnit 简介
- CUnit测试工具简介及下载地址
- CUnit测试工具简介及下载地址
- CUnit介绍
- cunit console
- cunit xml
- CUnit 安装
- 学习CUNIT
- CUnit单元测试
- CUnit使用
- CUnit使用说明
- CUnit介绍
- Cunit单元测试
- CUnit单元测试
- CUnit小试
- cUnit的简单例子
- PRTX P2P文件传输控件、组件功能说明
- rev
- 新的一周,打开一本新书—敏捷开发的艺术(Agile Development)
- Microsoft SQL Server 2000 Driver for JDBC在MyEclipse中的使用方法
- 搭建开发平台Eclipse
- Cunit简介
- 调和级数常数项的存在实验
- 范例框架开发方法——快速高效地进行Java Web应用开发
- Java多线程程序设计初步
- J2ME结构与相关规范介绍
- 在word中更改所有字母和数字的格式
- IIS转发多应用
- 手把手教你把Vim改装成一个IDE编程环境(图文)
- Oracle10g只有数据文件的恢复(Windows)