简体   繁体   中英

C++ Unit Testing and stubbing a 3rd party C library

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.

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).

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可以从头文件生成存根成员,除非你有特殊要求,它应该能够做你想要的。

You cant wrap those calls in a class like described in http://code.google.com/p/googlemock/wiki/CookBook#Mocking_Free_Functions

Then You can inject (in dynamic or static way) this class and set expectation on it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM