如何在谷歌模拟中自动生成模拟c

时间:2015-06-23 11:31:25

标签: c unit-testing gmock

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

我的问题的背景:

我有很多传统的c代码(不是c ++),需要通过google test和google mock进行单元测试。为了测试一个函数,我必须模拟由同一c源文件中的某些函数调用的数百个函数,即使它们没有被单元测试下的函数调用,否则,链接时会出现“未定义的引用”问题

1 个答案:

答案 0 :(得分:1)

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

来自doc:

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.