我正在使用Cmock +Cmock来测试我的方法。我一直在跟踪这个指南。在我的项目中,我有一个foo.h和foo.c文件:
foo.c:
#include <nfc/nfc.h>
#include <stdbool.h>
#include "foo.h"
void do_something_with_nfc() {
//... other code
// how might I mock this call? It is a method of nfc.h
bool result = nfc_initiator_transceive_bytes(pnd, msg, msg_len, buffer, buffer_len, 0);
}在我的test_foo.c文件中:
#include "mock_nfc.h" // should this include be <mock_nfc.h>, <nfc/mock_nfc.h> or "nfc/mock_nfc.h"?
#include "foo.h"
void test_do_something_with_nfc() {
// mocked behavior
nfc_initiator_transceive_bytes_IgnoreAndReturn(-1);
do_something_with_nfc();
}PROBLEM:我在运行“割让”时遇到的错误是:
ERROR: Found no file 'nfc.h' in search paths.libnfc是我安装的一个库,位于/usr/local/lib/libnfc (归档文件)。我对C开发非常陌生,但我认为CMock需要能够找到nfc.h头文件才能生成模拟。如果我只是简单地编译我的项目,我会添加-lnfc,所以我的下一步就是弄清楚Cmock/Cmock是如何需要传递这个信息的。为此,我查找了通过放弃的project.yml文件指定路径的方法:
:paths
:libraries: [/usr/local/lib, /usr/lib, /usr/local/lib/libnfc.a]即使进行了上述更改,我仍然会收到"nfc.h“未找到的错误。下载引用库的源代码(在本例中为libnfc)并将该源的路径添加到放弃的project.yml文件中是否更习惯呢?谢谢你的帮助。
发布于 2022-04-05 19:09:39
将以下内容添加到YML文件中,如果需要包含路径并查看其工作情况
:files:
:include:
- +:/usr/lib/**:paths:
:test:
- +:test/**
:source:
- src/**
- test/support/**
:include:
- include/**
:support:
:libraries: []
:files:
:include:
- +:/usr/lib/**如果你想试着测试符号功能,试着用下面的方式对我起作用。如何在C中模拟套接字
https://stackoverflow.com/questions/71743352
复制相似问题