Cover the patient with tests

Part 2 of 4 learning hours on this topic. All are specific for the C language.

Learning Goals

Session Outline

Connect - when do you have enough tests?

How do you know you have enough unit tests? Put a mark next to any you agree with.

Concept: Break dependencies using stubs

Last time we identified one problem with adding tests to existing code is to break dependencies. In the exercise repo Grep with Marketing there is a branch ‘with_stubs_no_tests’. It has the patient in the surgery, and each of the three dependencies is replaced by a stub implementation. Review the stub code.

Explain what a stub is and what problem it solves. Show how the link-time substitution works.

Concrete: add tests

Write tests for the patient, using the stubs. Aim for 100% code coverage.

Conclusions

In your own words, write down what a stub is and when you might use one.