【问题标题】:How the use unit test in cmake in language C?如何在 C 语言的 cmake 中使用单元测试?
【发布时间】:2016-07-05 09:29:05
【问题描述】:

我有一个 C 项目:

.
├── build
├── bin
│   └── parser
├── CMakeLists.txt
├── configure.h.in

├── inc
│   ├── configure.h
│   ├── diam_dict.h
│   └── unit_tests.h
├── README.txt
├── src
│   └── diam_dict.c
└── testing
    └── unit_tests.c

我想将单元测试放在目录“testing”的文件“unit_tests.c”中。
我想测试文件“src/diam_dict.c”的所有功能,我应该怎么做才能让“unit_tests.c”知道要测试的功能在哪里?
[我应该在文件“unit_tests.c”和顶级cmake文件“CMakeLists.txt”中写什么?]
(我应该调用源代码文件“diam_dict.c”的所有函数来测试它们)


ps:头文件“diam_dict.h”包含了源文件“diam_dict.c”中的所有函数原型,头文件“unit_tests” .h”包含测试文件“unit_tests.c”的所有原型。

【问题讨论】:

    标签: c unit-testing cmake


    【解决方案1】:

    CMake 是一个构建系统,因此您可以将它与您希望的任何单元测试框架结合起来。

    事实上,CTest 可以调用可执行文件并检查其结果值,这允许进行一些测试。但与专用单元测试框架中已知的真实单元测试相比,它通常没有那么精细。

    【讨论】:

    • 我实际上在这个项目中使用 CUnit。
    • 您的问题没有反映出这一点。
    猜你喜欢
    • 2011-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-24
    • 1970-01-01
    相关资源
    最近更新 更多