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
-
What inputs does a procedure accept?
-
What results does a procedure compute?
-
What side effects does a procedure cause?
-
What exceptions does a procedure activate?
-
What outputs does a procedure display?
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
-
Copy code you have inserted into the procedure as debugging infrastructure into unit tests.
-
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.
Категории