Characteristics of Unit tests

Using a list from Roy Osherove’s book “The Art of Unit Testing”.

Session Outline

Connect: Questioning whether you have unit tests

Ask yourself the following questions about the unit tests you’ve written up to now:

Add a tick or a cross to each to mark your answer.

If anyone answered ‘no’ to any question, point out that what they were doing was probably useful, but probably not a unit test in the sense that we are using this word.

Concept: Characteristics of good unit tests

Work in pairs to come up with characteristics, both by looking at the previous questions and by thinking about your own experience. After 5 minutes compare your list with the one below. Did you miss anything? Any extras?

According to Roy Osherove in his book “The Art of Unit Testing”, a unit test should have the following properties:

Concrete: Convert a main function into a test

Look at the “RecentlyUsedList” implementation. There is a main function you can use to test it. In what ways does this not fulfil the characteristics of a good unit test?

Re-write it as a unit test. When you’ve done that, add more tests to improve the coverage.

Conclusions: Note something you want to remember about unit test design

Perhaps something about the test framework or syntax or a characteristic of unit tests you want to remember.