9.3 Write a unit test


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

  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.




Debugging by Thinking. A Multidisciplinary Approach
Debugging by Thinking: A Multidisciplinary Approach (HP Technologies)
ISBN: 1555583075
EAN: 2147483647
Year: 2002
Pages: 172

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net