Random testing


Random testing is a black-box software testing technique where programs are tested by generating random, independent inputs. Results of the output are compared against software specifications to verify that the test output is pass or fail. In case of absence of specifications the exceptions of the language are used which means if an exception arises during test execution then it means there is a fault in the program, it is also used as way to avoid biased testing.

History of random testing

Random testing for hardware was first examined by Melvin Breuer in 1971 and initial effort to evaluate its effectiveness was done by Pratima and Vishwani Agrawal in 1975.
In software, Duran and Ntafos had examined random testing in 1984.

Overview

Consider the following C++ function:

int myAbs

Now the random tests for this function could be. Only the value '-35' triggers the bug. If there is no reference implementation to check the result, the bug still could go unnoticed. However, an assertion could be added to check the results, like:

void testAbs

The reference implementation is sometimes available, e.g. when implementing a simple algorithm in a much more complex way for better performance. For example, to test an implementation of the Schönhage–Strassen algorithm, the standard "*" operation on integers can be used:

int getRandomInput
void testFastMultiplication

While this example is limited to simple types, tools targeting object-oriented languages typically explore the program to test and find generators and call them using random inputs. Such approaches then maintain a pool of randomly generated objects and use a probability for either reusing a generated object or creating a new one.

On randomness

According to the seminal paper on random testing by D. Hamlet
the technical, mathematical meaning of "random testing" refers to an explicit lack of "system" in the choice of test data, so that there is no correlation among different tests.

Strengths and weaknesses

Random testing is typically praised for the following strengths:
The following weaknesses are typically pointed out by detractors:

With respect to the input

Some tools implementing random testing:
Random testing has only a specialized niche in practice, mostly because an effective oracle is seldom available, but also because of difficulties with the operational profile and with generation of pseudorandom input values.

A test oracle is an instrument for verifying whether the outcomes match the program specification or not. An operation profile is knowledge about usage patterns of the program and thus which parts are more important.
For programming languages and platforms which have contracts contracts act as natural oracles and the approach has been applied successfully. In particular, random testing finds more bugs than manual inspections or user reports.