开发者

Visual C++ overrides/mock objects for unit testing?

开发者 https://www.devze.com 2022-12-29 21:15 出处:网络
When I\'m running unit tests, I want to be able to \"stub out\" or create a mock object, but I\'m running into DLL Hell.

When I'm running unit tests, I want to be able to "stub out" or create a mock object, but I'm running into DLL Hell.

For example: There are two DLL libraries built: A.dll and B.dll -- Classes in A.dll have calls to classes in B.dll so when A.dll was built, the link line was using B.lib for the definti开发者_如何学运维ons.

My test driver (Foo.exe) is testing classes in A.dll, so it links against A.lib. However, I want to "stub out" some of the calls A.dll makes to B.dll with simple versions (return basic value, no DB look up, etc).

I can't build an Override.dll that just overrides the needed methods (not entire classes) and replace B.dll because Foo.exe will A) complain that B.dll is missing if I just remove it and put Override.dll in it's place or B) if I rename Override.dll to B.dll, Foo.exe complains that there are unresolved symbols because Override.dll is not a complete implementation of B.dll.

Is there a way to do this? Is there a way to statically link Foo.exe with A.lib, B.lib and Override.lib such that it will work without having to completely rebuild A.lib and B.lib to remove the __delcspec(dllexport)? Is there another option?


Linkers will only search the library if the function is not found in the list of linked object modules. The solution is to build your stubs into object modules that are linked with your test driver modules.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号