- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我最近开始从事一个用C语言编写的项目。为了添加单元测试用例,我搜索了 C 单元测试框架,并找到了这个答案 C-unittest-frameworks 。所以我选择了mocka并从installation steps安装它。但我知道如何运行书面测试用例。有人可以帮助我从命令行(GCC 命令)运行下面的简单单元案例:
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h> /* A test case that does nothing and succeeds. */
static void null_test_success(void **state) {
(void) state; /* unused */
}
int main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(null_test_success),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}
仅供引用,我指的是cmocka 。请告诉我除了 GCC 和 cmocka 之外还需要哪些依赖项。或者需要为 LD 路径等设置任何环境变量。
更新这个问题,我按照以下步骤操作:
1. git clone https://gitlab.com/cmocka/cmocka.git
2. cd cmocka && mkdir -p build && cd build/
3. cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=Debug -DUNIT_TESTING=ON ..
4. make && make install
毕竟,步骤,如果在构建目录中我执行ctest测试/,它正在运行所有测试用例。现在,我陷入了如何对我的项目执行相同步骤并运行虚拟单元测试用例的困境。
最佳答案
最后,经过在互联网上的更多研究,我发现了这篇关于如何使用 cmocka 运行单元测试用例的非常好的文章。这是链接run c unit test cases using cmocka .
我还 fork 了他的 git repo 并进行了相应的修改,也看看 git repo git code .
另外,我尝试了另一个框架gtest,看看gtest example code
关于c - 如何使用CMOCKA框架运行c单元测试用例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59817576/
我在文档和服务员示例中进行了搜索,但找不到有关如何检查正确的函数指针是否作为参数传递给函数的示例。 这个示例代码应该详细说明我的意思: void func_A(); void func_B(); vo
我已经下载了 cmocka example files并按照所有说明进行操作。所有测试文件都已成功生成,我可以运行它们,但控制台中没有输出。我曾尝试更改 CMOCKA_MESSAGE_OUTPUT 环
假设我声明了一个名为 foo 的 C 结构,它有一个名为 bar 的 int 字段和一个名为 baz 的 char *。 我如何使用 Cmocka expect_ 和 check_expected 宏
我正在开发一个项目 using the cmocka framework 。 cmocka主页指出 Test fixtures are setup and teardown functions tha
我有一个包含两个数据成员的简单结构。 typedef struct { int32_t x; int32_t y; } MyStructType; 我有一个按值返回结构的函数。 MyS
我正在使用 cmocka用于测试一些嵌入式 C 代码的库。根据文档,我使用 __wrap_ 前缀来模拟函数,这样我就可以隔离我的单元测试。但是,一旦我这样做,所有对该函数的调用将永远转到包装函数。我如
一点背景知识:我希望对构建到共享对象文件中的代码进行单元测试,例如libabc。此代码还调用 libjson-c 和 libcurl 函数。 我计划为产品代码中的每个函数编写函数测试,模拟从 liba
我正在尝试使用 cmocka 对一些源代码进行单元测试。基本上(相关的)源代码看起来类似于 Source.c。 单元测试分别调用每个函数。在测试 Add() 函数时,此函数最终将调用 util_mal
我正在尝试使用 cmocka 库在 c 中编写一个测试用例。我的测试用例正在测试一个函数,然后在内部调用来自第 3 方库的函数(无法修改库)。当应用程序不是时,此函数返回 NULL 值启动并运行,所以
我在 Ubuntu 下使用 Eclipse。 我刚刚安装了 cmocka: Install the project... -- Install configuration: "Debug" -- In
我刚刚开始使用 Cmocka,我已经在这个问题上停留了一段时间。我有一个正在尝试构建的 cmocka 项目。当我尝试使用“make”时,我看到了错误。 [ ERROR ] --- No entries
我有一个小型静态库项目,我正在将其从使用 Makefile 构建改写为现代 CMake,我正在尝试学习它。我的项目大量使用断言来检查先决条件,因此我编写了一个非常简单的自定义断言宏,它有条件地扩展为一
我正在学习 cmocka 单元测试框架。我对 mock() 函数的使用有点困惑。有人可以用合适的例子清楚地解释为什么以及如何使用它吗?还请说明何时应该使用它。 最佳答案 你应该阅读 https://l
我最近遇到了'cmocka ' C 的模拟库。我能够模拟单个函数并成功测试调用函数。现在我需要它来将它用于我正在从事的项目,在该项目中需要模拟大量功能。如何将我想要模拟的所有函数传递给 Linker
我能够使用 cmocka 并在屏幕上获得默认结果。我想获得 JUnit 格式的单元测试结果。 CMocka 通过使用环境变量 CMOCKA_MESSAGE_OUTPUT 或使用 API cmocka_
我很难使用 cmocka、测试 malloc 的失败(模拟)和使用 gcov 来找到一个小问题的答案 关于 cmocka+gcov 的更新:我注意到在我的 cmocka 测试中模拟一个函数后,我得到了
我安装了 CMocka testing framework并尝试了 sample code : #include #include #include #include /* A test ca
因此,玩具程序复制了我使用 cmocka 为现有代码开发单元测试时遇到的问题。问题是嵌套函数调用不模拟,这使得单元测试依赖于嵌套函数调用的正确执行。请注意,使用“mockable_static”定义是
我正在尝试在 Mac OSX Yosemite 10.10.3 上安装并运行 cmocka 库进行单元测试,但是我在 RPATH 方面遇到了一些问题设置。 更新: 感谢@baf,我能够像这样手动将 c
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我是一名优秀的程序员,十分优秀!