Tests Have Assertions

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: Test Design with assertions

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

The first thing about a test case is it has a name that must be unique. Usually you put it in a test class with the same name as the class being tested, so class “ABC” would have a test named “ABCTest”. Each test case is a test method in that class. Name the test method after the scenario you are testing. A test will usually fail if the code being tested throws an exception, but often you include an assertion to check what happened if no exception was thrown. Tests should fail if the thing you are testing has a bug in it.

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. For each method to be tested:


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