A Single Question

A test case answers a single question about the code it is testing. A test case should be able to…

  • …run completely by itself, without any human input. Unit testing is about automation.
  • …determine by itself whether the function it is testing has passed or failed, without a human interpreting the results.
  • …run in isolation, separate from any other test cases (even if they test the same functions). Each test case is an island.

Every test is an island.

Given that, let’s build a test case for the first requirement:

  1. The to_roman() function should return the Roman numeral representation for all integers 1 to 3999.

It is not immediately obvious how this code does… well, anything. It defines a class which has no __init__() method. The class does have another method, but it is never called. The entire script has a __main__ block, but it doesn’t reference the class or its method. But it does do something, I promise.

Get hands-on with 1400+ tech skills courses.