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.

Learning Goals

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 Parameterized tests are 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

Look back at the failure messages you compared in the Code Review. Does your parameterized test give feedback that’s just as useful when it fails?