Refactor the patient for testability

part 3 of 4 learning hours on this theme.

Learning Goals

Session Outline

Connect

In C, which of these allow you to substitute a different behaviour at:

There are four symbols and four proposals. Pair them up.

Using function pointers to insert a stub

In the exercise repo Grep with Marketing there is a branch ‘with_coverage’. The patient is in the surgery and fully covered with unit tests. We are ready to refactor it for testability. Explain that we need better seams so we can introduce stubs without using link-time substitution.

Refactor to function pointers

There are three stubs - it might be best to demo the first one. Introduce function pointers for each stub. This will also mean changes in the production code.

Conclusions

Go through the code listing for your final code. Write a comment // SEAM on any line of code you think is a seam. If you’re not finished with the refactoring, note there is a branch ‘with_abstractions’ which you can examine and annotate with SEAM comments.

Compare your answers with someone else and discuss any differences. Explain to the other person how you’d define a Seam.