这件事正在引起悲伤;我想掌握 CUnit。
已使用以下说明安装它: http://macappstore.org/cunit/
我在命令行中使用以下命令: gcc myprog.c -Wall -Wfloat-equal -Wextra -O2 -pedantic -ansi -lm -lcunit -o myprog
它编译没有错误,我继续执行以下操作: ./myprog
我的代码中有以下内容:
#include <stdio.h>
#include <math.h>
#include <CUnit/CUnit.h>
int maxi(int i1, int i2);
void test_maxi(void);
struct code{
char words[5][5];
int cnt; /* Current Word Counter*/
};
typedef struct code Code;
int main(void){
test_maxi();
return 0;
}
int maxi(int i1, int i2){
return (i1 > i2) ? i1 : i2;
}
void test_maxi(void){
CU_ASSERT(maxi(0,2) == 2);
CU_ASSERT(maxi(0,-2) == 0);
CU_ASSERT(maxi(2,2) == 2);
}
我的假设是,这应该在同一目录中生成某种 .txt 或替代文件。这个假设不正确吗?我应该寻找什么?
更新:我目前在命令行上得到以下信息; “断言失败:(NULL != f_pCurSuite),函数 CU_assertImplementation,文件 TestRun.c,第 162 行。 中止陷阱:6"
(全面披露:编程新手......所以要温柔:P)
最佳答案
您没有在 main()
中调用 test_maxi
,因此它只是作为函数存在,但并未运行。您需要在 main
中运行它。
——伊莱·萨多夫
您需要按照说明创建一个测试套件 here 。 – PBN
关于c - 单元测试: CUnit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41250846/