Random testing explained

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 a 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.[1]

In software, Duran and Ntafos had examined random testing in 1984.[2]

The use of hypothesis testing as a theoretical basis for random testing was described by Howden in Functional Testing and Analysis. The book also contained the development of a simple formula for estimating the number of tests n that are needed to have confidence at least 1-1/n in a failure rate of no larger than 1/n. The formula is the lower bound nlogn, which indicates the large number of failure-free tests needed to have even modest confidence in a modest failure rate bound.[3]

Overview

Consider the following C++ function:

int myAbs(int x)

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(int n)

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(int n)

While this example is limited to simple types (for which a simple random generator can be used), tools targeting object-oriented languages typically explore the program to test and find generators (constructors or methods returning objects of that type) and call them using random inputs (either themselves generated the same way or generated using a pseudo-random generator if possible). 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.[4]

Strengths and weaknesses

Random testing is praised for the following strengths:

The following weaknesses have been described :

Types of random testing

With respect to the input

Guided vs. unguided

Implementations

Some tools implementing random testing:

Critique

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.[4]

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 (e.g. Eiffel. .NET or various extensions of Java like JML, CoFoJa...) contracts act as natural oracles and the approach has been applied successfully.[7] In particular, random testing finds more bugs than manual inspections or user reports (albeit different ones).[8]

See also

External links

Notes and References

  1. Probabilistic Analysis of Random Test Generation Method for Irredundant Combinational Logic Networks. P.. Agrawal. V. D.. Agrawal. 1 July 1975. IEEE Transactions on Computers. C-24. 7. 691–695. 10.1109/T-C.1975.224289.
  2. An Evaluation of Random Testing. J. W.. Duran. S. C.. Ntafos. 1 July 1984. IEEE Transactions on Software Engineering. SE-10. 4. 438–444. 10.1109/TSE.1984.5010257.
  3. Book: Howden, William. Functional Program Testing and Analysis. McGraw Hill. 1987. 0-07-030550-1. New York. 51-53.
  4. Book: Encyclopedia of Software Engineering. 1994. John Wiley and Sons. 978-0471540021. Richard Hamlet. 1st. John J. Marciniak. Random Testing.
  5. Web site: Is it a bad practice to randomly-generate test data?. stackoverflow.com. 15 November 2017.
  6. Pacheco. Carlos. Shuvendu K. Lahiri . Michael D. Ernst . Thomas Ball . Feedback-directed random test generation. ICSE '07: Proceedings of the 29th International Conference on Software Engineering. May 2007. 75–84. 0270-5257.
  7. Web site: AutoTest - Chair of Software Engineering. se.inf.ethz.ch. 15 November 2017.
  8. On the number and nature of faults found by random testing. 2009. Ilinca Ciupa. Alexander Pretschner. Manuel Oriol. Andreas Leitner. Bertrand Meyer. Software Testing, Verification and Reliability. 10.1002/stvr.415. 21. 3–28.