Loading the lesson...
In the print dialog, choose "Save as PDF" as the destination.
Software Construction - Lab 3
Validation, test-first programming, black-box and white-box techniques, and coverage.
Validation
Verification
A formal proof of correctness; tedious by hand, tooling still a research area
Code Review
Someone else reads your code and reasons about it informally
Testing
Run the program on selected inputs and check the results
1,000 lines of source)| Defects per kloc | Quality level | Examples |
|---|---|---|
1 - 10 | Typical industry software | Most commercial software |
0.1 - 1 | High-quality validation | Java libraries |
0.01 - 0.1 | Safety-critical validation | NASA, Praxis |
32-bit floating-point multiply a*b alone has 2^64 possible test cases.When you're coding, the goal is to make the program work. When you're testing, the goal is to make it fail.
Testing Techniques
Specification-Based
Black-box: test cases chosen only from the spec
Structure-Based
White-box: test cases chosen with knowledge of the implementation
Experience-Based
Driven by tester skill, intuition and past failures
Worked Example
BigInteger.multiply/**
* @param val another BigInteger
* @return a BigInteger whose value is (this * val)
*/
public BigInteger multiply(BigInteger val)multiply takes a two-dimensional input space: every pair of integers (a, b)a or b is 0, 1, or -1a or b is small, or its absolute value exceeds Long.MAX_VALUE (roughly 2^63), since a suspicious tester assumes the implementation optimizes with int/long internallydef absolute_value(x):
if x < 0:
x = -x
return xx = 5: how many of the three statements does it execute?1 and 3 only, skipping the negation on line 2: 66% statement coverage (2 of 3)x = -5 executes all three lines: 100% statement coverage| Aspect | Unit test | Integration test |
|---|---|---|
| Scope | Single module | Multiple modules |
| Speed | Fast | Slower |
| Debugging | Easy | Harder |
| When it fails | Bug is in this module | Bug could be anywhere |
| Purpose | Test logic | Test connections |
Mahmoud Abas|Software Construction - Lab 3: Software Testing Techniques