Test Oracle

Strictly speaking, the test oracle does not belong to this list because it does not specify an intrinsic quality of the operation. Still, it is a useful and convenient way to pinpoint an expected behavior.

The principle is simple and especially useful during a refactoring or rewriting of the existing system. It uses given trusted implementation to verify the behavior of the new code. Back to our string examples, we might use Java's Array as a test oracle for the sorting of the contents of the string, by expecting that the results of sorting the string and an array, which consists of its elements, would be the same:

scala> forAll { a: String =>
| val chars = a.toCharArray
| java.util.Arrays.sort(chars)
| val b = String.valueOf(chars)
| a.sorted == b
| }.check
+ OK, passed 100 tests.

But, of course, in the real refactoring scenario on the place of an array, the existing implementation would be used.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.76.72