使用:cc -o test testtest.c -lcunit编译它,但仍然无法正确运行测试。他们由于某种原因崩溃了:)
我正在做一个项目,最近我说服自己我应该继续采用测试驱动的方法。主要是因为项目本身正在增长,我想要证明所有功能都有效。
但是我在做 cunit 教程时遇到了一些问题。 http://cunit.sourceforge.net/doc/writing_tests.html
这是我的 cunit 测试文件:
#include <CUnit/CUnit.h>
main(){
test_maxi();
}
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);
}
当我尝试编译它时出现这些错误:
testtest.c:(.text+0x62): 未定义对
CU_assertImplementation' testtest.c:(.text+0x9b): undefined reference to
CU_assertImplementation 的引用 testtest.c:(.text+0xd5): 未定义对 `CU_assertImplementation' 的引用 collect2: ld 返回 1 个退出状态
我使用谷歌,我认为它与链接有关?但我并没有从中得到太多帮助。
最好的问候里卡德