Debugging by Thinking: A Multidisciplinary Approach (HP Technologies)

9.3 Write a unit test

9.3.1 Basic tactic

Write a test that invokes a procedure in question and compares its result or side effects with an expected result that is embedded in the test procedure.

9.3.2 Purpose

Determine whether a specific procedure is functioning as you expect it should.

9.3.3 Questions answered

9.3.4 Potential problems

Complex procedures may require many unit tests to test thoroughly. Knowing when you have a complete set can be difficult.

9.3.5 Refined tactics

  1. Copy code you have inserted into the procedure as debugging infrastructure into unit tests.

  2. Copy code you executed in a debugger to exercise the procedure into unit tests.

9.3.6 Related tactics

Use a unit testing framework such as JUnit. Unit testing frameworks for many other programming languages are also available. See our Website for further information.

Категории