Title: What is a stub? Date: 2016-07-01 23:39 Author: eamonnfaherty Category: testing Slug: what-is-a-stub Status: draft
I was recently at a python talk where there was a great presentation on testing. It covered the concepts of mocks, magic mocks and patches but it did not cover stubs. I found this omission interesting and then I looked through the python code at my place of work and realised that the python code I was looking at always tested using mocks and never used stubs.
Before I jump into the definition it is good to recap some of the basics:
- The class you are testing is called the subject under test or sut
- If your class works with in conjunction with other classes these are called collaborators
- When you are testing your class you should replace non simple collaborators with test doubles
Mocks are a type of test double but they are not the only type. You can replace your collaborator with another type of test double - a stub.