Can anyone tell me very clearly what\'s the main difference between a shim
and a stub
during unit testing?
I know about mock objects and I
Let me cite Martin Fowler's article Mocks Aren't Stubs:
Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test. Stubs may also record information about calls, such as an email gateway stub that remembers the messages it 'sent', or maybe only how many messages it 'sent'.
Mocks are [...] objects pre-programmed with expectations which form a specification of the calls they are expected to receive.
So mocks can directly make a test fail if an expectation is violated. Stubs don't do that.
Shims (or Moles) differ from both of them in that they can be used to replace hard-coded dependencies like static methods. You should avoid that IMO and prefer a refactoring, which makes these dependencies replaceable. See this thread for further discussion, especially Jim Cooper's answer.