views:

77

answers:

1

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

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?

A: 

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.

Bruce
The problem is there is a __delcspec(dllimport/dllexport) macro on the class in the header file for the class in B.dll. My understanding is that tells the linker to look in an external dll for the implementation of this class. Because of this, I don't think I can do the override that way without taking modifying the included header.Creating the .obj results in a "inconsistent dll linkage" warning, and running Foo.exe still ignores the override.
Mark