C++ 单元测试和存根第 3 方 C 库 [英] C++ Unit Testing and stubbing a 3rd party C library

查看:31
本文介绍了C++ 单元测试和存根第 3 方 C 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对我编写的一些使用 3rd 方 C 库的 C++ 对象进行单元测试.由于超出本问题范围的原因,我无法直接调用 3rd 方 C 库,需要将其存根以用于测试套件.

I need to unit test some C++ objects that I've written that use a 3rd party C library. For reasons beyond the scope of this question, I can't call the 3rd party C library directly, and need to stub it out for the test suite.

对于我们单元测试套件的其他部分,我们使用 googlemock,但我认为它不能用于 C 库.我可以手动删除库,但不喜欢(部分原因是懒惰(它相当大),但主要是因为它只是一个原则问题).

For other parts of our unit test suite we use googlemock, but I don't think it can be used for C libraries. I can stub out the library manually, but prefer not to (partly due to laziness (its rather large), but mainly because its just a matter of principles).

所以这是我的问题:是否有一种工具可以根据 C 库头文件生成存根代码?一旦我得到了删减的代码,我就会对它做一些小的修改,然后我会链接它进行单元测试.

So here's my question: is there a tool that generates stubbed code based on a C library header file? Once I have the stubbed-out code, I'll do some minor mods to it, then I'll link against it for the unit testing.

推荐答案

stubgen 可以从头文件生成存根成员,除非您有特殊要求,否则它应该能够满足您的要求.

stubgen can generate stub members from header files, unless you have special requirements it should be able to do what you're looking for.

这篇关于C++ 单元测试和存根第 3 方 C 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆