Parameterized Tests in Doctest

This is a form of Data-Driven testing. The “Act” step is the same for all the tests, but the Arrange and Assert parts are parameterized.

Session Outline

Connect: explain test design concepts

Explain previous concepts:

Code Review: Shopping Basket

Review the test cases in Shopping Basket Test Design Kata. Insert a bug (change 0.05 to 0.07 so the five percent discount case is wrong) and run the tests. Look at the failure messages. Which test design gives the best feedback?

Concept: Parameterized Tests

Explain that this is a form of Data-Driven testing. The “Act” step is the same for all the tests, but the Arrange and Assert parts are parameterized. Show how to do this with Doctest (ie it’s not very easy at present).

Do: Write some parameterized tests

Ask them to write new tests for the Shopping Basket implementation. When they have them working, ask them to re-insert the bug so one of the cases fails. Make sure the feedback is useful.

Reflect: Test Design

Note down your most important takeaways on the topic of Test Design.