Title: Testing and Debugging
1Testing and Debugging
a good tester is one who likes to break things!
a good tester is one who likes to fix things!
- Testing is the process of trying to force
software to exhibit its defects (violations of
contracts) - Debugging is the process of identifying and
fixing such defects
2Testing a Class Step 1
this is normally an entire class, not just a
single method
a good way to present a test case is with a
tracing table
- Create a test plan, i.e., a set of test cases,
each of which has - A set of input values to a method of the unit
under test (UUT) - A set of expected output values, based on the
methods contract
3Testing a Class Step 2
this can be tricky
- Carry out the test plan, i.e., write a test
driver program that for each test case - Constructs the test case input values of the test
case - Executes the method
- Compares the actual output values of the method
to the expected output values of the test case
this can be tricky
this is often just main in the UUT!
4Test Case Selection
sometimes called black-box testing
sometimes called white-box testing or clear-box
testing
- Test cases can be
- Specification-based, i.e., selected based on the
interface contract the UUT is supposed to
implement - Code-based, i.e., selected based on the code of
the UUT - What are some pros and cons of both?
5Test Coverage Black Box
- Partition the input space and output space for
each method based on the contract (look at the
requires/ensures clauses, respectively) - Include at least one test case from each partition
one good way to partition is to identify extreme
cases in the specification
6Test Coverage White Box
if (condition) branch1 else branch2
if (conditionA) branch1 else
branch2 if (conditionB) branch3 else
branch4
each of these is stronger than the one before it
- Statement coverage
- Make sure each statement is executed at least
once - Branch coverage
- Make sure each branch is executed at least once
- Path coverage
- Make sure each path is executed at least once