Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

This questionquestion on SO gives a pretty good understanding on the difference of each. It is subtle but it is still there. In short stubs are dumb, pre-recorded set of answers for a specific test. They are not usually very re-usable and are only basic plugs to test a specific class. Mocks are smarter in that you can configure them dynamically and question them afterwards on the interactions the tested class submitted them to.

Getting this right is important if your team uses both for specific uses. Swapping the terms in this conditions will lead to some confusion about the required task : "Stub this class with limit data for your test" to me implies a different test than "mock the dependencies for your test". In the first stubs just dumbly return fake values that will allow me to test specific values. the second implies that I have to also test the interactions between the tested class and it's dependencies. Nothing prevents me though from implementing the stubs with the same mocking framework (effectively creating a dumb mock) but it is much harder to create a mock from a stub.

That said, nSubstitute seems to pretty much solve this by merging all the concepts under one address. At which point the debate is pretty much academic.

Thanks for the link :-)

This question on SO gives a pretty good understanding on the difference of each. It is subtle but it is still there. In short stubs are dumb, pre-recorded set of answers for a specific test. They are not usually very re-usable and are only basic plugs to test a specific class. Mocks are smarter in that you can configure them dynamically and question them afterwards on the interactions the tested class submitted them to.

Getting this right is important if your team uses both for specific uses. Swapping the terms in this conditions will lead to some confusion about the required task : "Stub this class with limit data for your test" to me implies a different test than "mock the dependencies for your test". In the first stubs just dumbly return fake values that will allow me to test specific values. the second implies that I have to also test the interactions between the tested class and it's dependencies. Nothing prevents me though from implementing the stubs with the same mocking framework (effectively creating a dumb mock) but it is much harder to create a mock from a stub.

That said, nSubstitute seems to pretty much solve this by merging all the concepts under one address. At which point the debate is pretty much academic.

Thanks for the link :-)

This question on SO gives a pretty good understanding on the difference of each. It is subtle but it is still there. In short stubs are dumb, pre-recorded set of answers for a specific test. They are not usually very re-usable and are only basic plugs to test a specific class. Mocks are smarter in that you can configure them dynamically and question them afterwards on the interactions the tested class submitted them to.

Getting this right is important if your team uses both for specific uses. Swapping the terms in this conditions will lead to some confusion about the required task : "Stub this class with limit data for your test" to me implies a different test than "mock the dependencies for your test". In the first stubs just dumbly return fake values that will allow me to test specific values. the second implies that I have to also test the interactions between the tested class and it's dependencies. Nothing prevents me though from implementing the stubs with the same mocking framework (effectively creating a dumb mock) but it is much harder to create a mock from a stub.

That said, nSubstitute seems to pretty much solve this by merging all the concepts under one address. At which point the debate is pretty much academic.

Thanks for the link :-)

Source Link
Newtopian
  • 7.2k
  • 3
  • 37
  • 52

This question on SO gives a pretty good understanding on the difference of each. It is subtle but it is still there. In short stubs are dumb, pre-recorded set of answers for a specific test. They are not usually very re-usable and are only basic plugs to test a specific class. Mocks are smarter in that you can configure them dynamically and question them afterwards on the interactions the tested class submitted them to.

Getting this right is important if your team uses both for specific uses. Swapping the terms in this conditions will lead to some confusion about the required task : "Stub this class with limit data for your test" to me implies a different test than "mock the dependencies for your test". In the first stubs just dumbly return fake values that will allow me to test specific values. the second implies that I have to also test the interactions between the tested class and it's dependencies. Nothing prevents me though from implementing the stubs with the same mocking framework (effectively creating a dumb mock) but it is much harder to create a mock from a stub.

That said, nSubstitute seems to pretty much solve this by merging all the concepts under one address. At which point the debate is pretty much academic.

Thanks for the link :-)