【发布时间】:2016-12-20 20:35:23
【问题描述】:
这件事引起了悲伤;我想掌握 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中运行它。 -
感谢@EliSadoff。那很有帮助。我只是在 main 中添加了一行,即“ test_maxi(); ”。在命令行上,我得到以下信息:断言失败:(NULL!= f_pCurSuite),函数 CU_assertImplementation,文件 TestRun.c,第 162 行。中止陷阱:6 你能详细说明吗?(如果我以有点慢,对这一切有点新)
-
请将您的实际代码添加到问题中,
int main(void) { return 0; }发布的代码没有任何作用。 -
是的,我太傻了。我已经相应地更新了它:)
-
您需要按照here 的说明创建一个测试套件。
标签: c unit-testing command-line cunit