参考链接
http://blog.chinaunix.net/uid-13182088-id-2904570.html
【1】CUnit在Linux服务器安装
安装步骤:参考路径http://blog.163.com/soyking@126/blog/static/1621252512014622059667/
也可以解压后直接看README文件
bzip2 -d CUnit-2.1-3.tar.bz2
tar xvf CUnit-2.1-3.tar
cd CUnit-2.1-3/
aclocal
autoconf
automake
(上一步如果出错 先执行
autoheader
automake --add-missing)
chmod u+x configure
./configure --prefix /home/longhui/program_cunit
(上一步如果出错 先执行
libtoolize
./configure --prefix /home/longhui/program_cunit
)
make
make install
【2】编写测试工程,验证cunit安装是否成功,软件用法
参考链接
http://blog.csdn.net/scucj/article/details/4385630#
可运行的代码
【3】MainModule.c
CUnit-List.dtd
http://blog.chinaunix.net/uid-13182088-id-2904570.html
【3】关于CUnit测试原理的讲解
http://blog.csdn.net/jia870723/article/details/8574270
http://blog.csdn.net/jiantiantian/article/details/3546887
目录完整介绍
http://blog.chinaunix.net/uid-13182088-id-2904570.html
【1】CUnit在Linux服务器安装
安装步骤:参考路径http://blog.163.com/soyking@126/blog/static/1621252512014622059667/
也可以解压后直接看README文件
bzip2 -d CUnit-2.1-3.tar.bz2
tar xvf CUnit-2.1-3.tar
cd CUnit-2.1-3/
aclocal
autoconf
automake
(上一步如果出错 先执行
autoheader
automake --add-missing)
chmod u+x configure
./configure --prefix /home/longhui/program_cunit
(上一步如果出错 先执行
libtoolize
./configure --prefix /home/longhui/program_cunit
)
make
make install
【2】编写测试工程,验证cunit安装是否成功,软件用法
参考链接
http://blog.csdn.net/scucj/article/details/4385630#
可运行的代码
【1】main.c
#include <stdio.h>
#include <assert.h>
#include "Console.h"
extern int AddTestMainModule(); /* 测试用例函数定义在TestMainModule.c */
int main()
{
/* 1初始化一个Registry */
if( CUE_SUCCESS != CU_initialize_registry())
{
return CU_get_error();
}
/* 2返回注册到用例指针 */
assert(NULL != CU_get_registry());
/* 3检测是否在执行 */
assert(!CU_is_test_running());
/* 4调用自定义的测试模块完成测试用例 */
if (0 != AddTestMainModule())
{
CU_cleanup_registry();
return CU_get_error();
}
#if 0
/*
5测试结果有两类显示方式:一类是交互时,另一类是生成xml测试报告;具体有四种接口:
Cunit提供四种编程接口,通常是针对不同类型的程序需求(1)使用console控制交互界面的函数入口 Automated Output to xml file
*/
CU_console_run_tests();
#else
/*
**使用自动产生XML文件的模式*******
要查看这两个文件,还需要使用如下xsl和dtd文件:
CUnit-List.dtd和CUnit-List.xsl用于解析列表文件,
CUnit-Run.dtd和CUnit-Run.xsl用于解析结果文件。
这四个文件在CUnit包里面有提供,安装之后在unittest/share/CUnit目录下,
默认安装的话在/home/usr/local/share/CUnit目录下。
在查看结果之前,需要把这六个文件:
TestMax-Listing.xml, TestMax-Results.xml, CUnit-List.dtd, CUnit-List.xsl, CUnit-Run.dtd, CUnit-Run.xsl拷贝到一个目录下,然后用浏览器打开两个结果的xml文件就可以了。
*/
CU_set_output_filename("TestMax"); /*设置生成的xml测试文件名*/
CU_list_tests_to_file();
CU_automated_run_tests();
#endif
/* 6测试完毕后清理Registry */
CU_cleanup_registry();
return 0;
}
【2】Makefile
########################################################
##Standard Makefile for single C file
##Version:1.0 Date:20150921 Author:David Long
##参考链接http://blog.csdn.net/jiayanhui2877/article/details/8622073
#######################################################
#编译环境
CC = gcc
#默认包含本目录的include目录作为头文件搜索路径 CUnit的头文件和库文件的路径
INC = -I/home/longhui/program_cunit/include/CUnit
LIB = -L/home/longhui/program_cunit/lib
#生成的目标可执行文件名
Target=test
#源文件
MainFile=MainModule.c TestMainModule.c main.c
$(Target):$(MainFile)
$(CC) $(MainFile) -o $(Target) $(INC) $(LIB) -lcunit -static
.PRONY:clean
clean:
@echo "Removing linked and compiled files......"
rm -f *~ *.o *.xml $(Target)
【3】MainModule.c
#include "MainModule.h"
计算两个数之和
int cal_num(int a, int b)
{
int c;
c = a + b;
return c;
}
【4】MainModule.h
#ifndef __MAIN_MODULE_H__
#define __MAIN_MODULE_H__
#include <stdio.h>
//计算两个数之和
int cal_num(int a, int b);
#endif
【5】
CUnit-List.dtd
CUnit-List.xsl
CUnit-Run.dtd
CUnit-Run.xsl
http://blog.chinaunix.net/uid-13182088-id-2904570.html
【3】关于CUnit测试原理的讲解
http://blog.csdn.net/jia870723/article/details/8574270
http://blog.csdn.net/jiantiantian/article/details/3546887
目录完整介绍