Unit Tests Should Find Bugs

This learning hour is about basic test design including assertions.

Learning Goals

Session Outline

Connect: Three facts

What is an automated unit test? Give me three facts about it.

Concept: Unit Test Design

Briefly explain the most important things about test design. For example:

A unit test should fail if the thing you are testing has a bug in it. We are trying to achieve Self Testing Code. When a test fails you want to understand as quickly as possible what is wrong. Show a failing test in a test runner. Point out how to find the test name, the failure message, and how to navigate to the line of code responsible.

Make sure they have access to the documentation for their test framework. Explain how to assert for equality and assert that an exception is thrown.


Write some test cases for some existing code that has well-marked bugs in. For example CalcStats. Make sure to explain what the code is supposed to do as well as that it also contains bugs that are not marked.



What is important to remember when writing unit tests? Explain the main idea