Test cases can be derived in two ways, by looking inside the program or by looking only at what it should do.
Functional Testing (Black Box)
In functional testing, the tester uses only the specification and does not look at the code. It checks that the functions work as required. Equivalence class partitioning divides the input domain into classes, such that all values in a class should be treated in the same way, and takes one test from each valid and invalid class. Boundary value analysis tests the values at the edges of a class, since errors often occur there. For a mark field that accepts 0 to 100, the test values are -1, 0, 1, 99, 100 and 101. Cause-effect graphing and decision tables show combinations of conditions and the resulting actions. Error guessing uses experience to guess the places where errors are likely.
Definition: Black-box testing. A testing method in which test cases are designed from the specification of the software, without knowledge of its internal structure.
Structural Testing (White Box)
In structural testing, the tester uses the code. The coverage criteria are statement coverage, in which every statement is executed at least once, branch coverage, in which every decision takes both true and false outcomes, condition coverage, in which each condition in a decision takes both values, and path coverage, in which every path is executed. Path coverage is the strongest but is impractical with loops. Basis path testing uses the cyclomatic complexity V(G) = E - N + 2 of the control flow graph to find the number of independent paths, and a test case is made for each. Loop testing tests loops with zero, one, two, a typical and the maximum number of passes.
Comparison
Black-box tests can be made early from the SRS, and need no knowledge of the code, but may not exercise all the code. White-box tests make sure that the code has been exercised, but do not find missing functions. Both are used, with black-box testing at higher levels and white-box testing at the unit level.
Table 3.7: Black-box and white-box testing
| Aspect | Black box | White box |
|---|---|---|
| Based on | Specification | Code structure |
| Needs code | No | Yes |
| Methods | Equivalence classes, boundary values | Statement, branch, path coverage |
| Finds | Missing and wrong functions | Unexecuted or faulty code |
Example 3.7: Boundary values and cyclomatic complexity
Problem: (a) A form accepts ages from 18 to 60 inclusive. List the boundary value tests. (b) A program has a control flow graph with 9 edges and 7 nodes. Find V(G).
Solution:
- The boundary tests are 17, 18, 19, 59, 60 and 61.
- V(G) = E - N + 2 = 9 - 7 + 2 = 4.
Result: Six boundary tests, and four independent paths, so at least four test cases for basis path testing.
lo, hi = 18, 60
tests = [lo - 1, lo, lo + 1, hi - 1, hi, hi + 1]
print(tests, [lo <= a <= hi for a in tests])
print("V(G) =", 9 - 7 + 2)
Output
[17, 18, 19, 59, 60, 61] [False, True, True, True, True, False]
V(G) = 4
Common mistakes
- Testing only values from the middle of a valid range.
- Taking 100 percent statement coverage to mean that the program is correct.
- Using white-box tests only, and missing functions that were never coded.
Key takeaways
- Black-box testing uses the specification, and white-box testing uses the code.
- Equivalence classes and boundary values are black-box techniques.
- Statement, branch and path coverage are white-box criteria.
- V(G) = E - N + 2 gives the number of independent paths.
Practice questions
- What is boundary value analysis?
- Name three coverage criteria of white-box testing.
- What does cyclomatic complexity give?
Answers to the practice questions
- Testing values at and next to the edges of the input classes.
- Statement coverage, branch coverage and path coverage.
- The number of independent paths in a program.
Sources
- Official BCA syllabus Advanced Software Engineering, course code 25BCA405DS01, Unit III
