c - 单元测试: CUnit

标签 c unit-testing command-line cunit

这件事正在引起悲伤;我想掌握 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/

相关文章:

Java 命令行尖括号

c - 需要左值作为赋值的左操作数 - 编译错误不清楚

Spring Boot 测试失败, 'No bean named ' webHandler'可用'

python - 在 Python 中伪造回溯

angular - 如何在 Angular 应用程序中对 router.navigate 进行单元测试

ubuntu - 如何在 Ubuntu 中强制杀死进程?

windows - 如何使用 REST+cURL 更新 TeamCity 构建参数

C语言int num转char字符串

c - 使用生产者和消费者,C 中的信号量

c - 如何使用 C 与 COM 对象交互?