the way you describe how to replace the real class with the mock at
link time definitely is a lot of work. I personally wouldn't do that,
as there are (in my opinion better) alternative solutions:
- do not instantiate objects of classes you depend on in your class
under test, but create those objects outside the class and give them
to the class at construction time (this pattern is called "dependency
injection"). Obviously you don't want to do this for all classes (for
example, simple collections or strings). My personal rule of thumb is
that if I don't want to inject a dependency I probably don't want to
use mocks for testing (they introduce strong coupling on specific
interactions instead of the interface)
- if you don't want to create and hand in a mock object, but want to
usually do the setup and creation of the depended on class in your
class under test, create a way to be able to inject the mock object
after creation. This is slightly "dirty" in that it adds normally
unneeded clutter to your class under test, so use it only when the
other option is not available
- don't use mocks; mocks are not always the right way to test a class
- from your description I have no idea what the responsibility of the
class you want to mock is, so I can't give advice there
Cheers,
/Manuel