Stubs are canned responses to calls made during a test, whereas mocks are meant to set expectations. They can be further explained as follows:
- Stubs: In the stubs object, we always get a valid stubbed response. The response doesn't care what input you provided. In any circumstance, the output will be the same.
- Mocks: In the mock object, we can test or validate methods that can be called on mocked objects. This is a fake object that validates whether a unit test failed or passed. In other words, we can say that mock objects are just replicas of our actual object.
In the previous section, Writing unit tests, we used the moq framework to implement the mocked objects.