Testing is the main way of finding the errors that remain in a program. It is a large part of the cost of a project, so it must be planned well.

Testing and Its Objectives

Software testing is the process of running a program with the aim of finding errors. A good test case is one that has a high probability of finding an error that has not yet been found. Testing can show that errors are present, but it cannot show that there are none. A failure is the incorrect behaviour that is seen, a fault or defect is its cause in the code, and an error is the mistake of the human that put the fault there.

Definition: Software testing. The process of executing a program with the intention of finding errors.

Impracticality of Exhaustive Testing

To be sure that a program is correct, one would have to try every possible input and every path. This is impractical. A function with two integer inputs of 32 bits each has 2 to the power 64 input pairs, which would take billions of years to run, even at a billion tests per second. The number of paths through a program with loops is also very large. Testing therefore has to select a small set of test cases that are likely to find the most errors, and this is why systematic methods such as equivalence classes and boundary values are used.

Levels of Testing

Testing is done at several levels, each of which has a different aim. Unit testing checks each module by itself, with drivers and stubs. Integration testing combines the modules and tests their interfaces, using top-down, bottom-up or big-bang approaches. System testing tests the complete system against the SRS, and includes tests of performance, security and recovery. Acceptance testing is done by the customer, to decide whether to accept the system, with alpha testing at the developer's site and beta testing at the customer's site. Regression testing repeats the earlier tests after any change.

Table 3.6: Levels of testing

Level Checks Done by
Unit A single module Programmer
Integration Interfaces among modules Programmer or tester
System Whole system against the SRS Test team
Acceptance Fitness for the customer Customer

Example 3.6: Why exhaustive testing fails

Problem: A function takes two 16-bit integers. If one test takes a millisecond, how long would exhaustive testing take?

Solution:

  1. The number of input pairs is 2 to the power 16 times 2 to the power 16, which is 2 to the power 32 = 4294967296.
  2. At 1000 tests per second the time is 4294967296 / 1000 seconds = 4294967 seconds.
  3. This is 4294967 / 86400 = 49.7 days.

Result: Even for a tiny function, exhaustive testing takes about 50 days, and for 32-bit inputs it is impossible.

pairs = 2 ** 16 * 2 ** 16
seconds = pairs / 1000
print(pairs, round(seconds / 86400, 1), "days")

Output

4294967296 49.7 days

Common mistakes

  • Believing that a program that passes its tests has no errors.
  • Testing only the cases that are expected to pass.
  • Skipping regression tests after a small change.

Key takeaways

  • Testing finds errors but cannot prove their absence.
  • Exhaustive testing is impractical.
  • The levels are unit, integration, system and acceptance.
  • Regression testing repeats earlier tests after a change.

Practice questions

  1. Why is exhaustive testing impractical?
  2. Name the levels of testing.
  3. Distinguish a fault from a failure.

Answers to the practice questions

  1. The number of inputs and paths is far too large to test in a reasonable time.
  2. Unit, integration, system and acceptance testing.
  3. A fault is the defect in the code, a failure is the incorrect behaviour that results.

Sources

  • Official BCA syllabus Advanced Software Engineering, course code 25BCA405DS01, Unit III