如何在谷歌mock for c中自动生成mock

How to generate mock automatically in google mock for c

本文关键字:mock 自动生成 for 谷歌      更新时间:2023-10-16

我知道google mock中有一个名为gmock_gen.py的工具,可以用来自动生成c++类的mock。有没有类似的工具可以为c函数生成mock,给定一个c源文件,我想在其中模拟这些函数?

我问题的背景:

我有很多遗留的c代码(不是c++)需要通过谷歌测试和谷歌模拟进行单元测试。要测试一个函数,我必须模拟同一个c源文件中某些函数调用的数百个函数,即使它们不是单元测试中的函数调用的,否则,链接时会出现"未定义引用"问题。

也许你可以看看这个github repo:https://github.com/hjagodzinski/C-Mock

来自文档:

C Mock is Google Mock extension allowing for mocking functions.

This is not either a patch to nor fork of Google Mock. This is just a set of headers providing a way of using tools for mock methods with mock functions in tests.

C Mock is not intended to promote bad design. Its goal is to help people test their code.