Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a test oracle and what is it used for?

Tags:

I don't really understand the concept of a software testing oracle. It says:

An oracle is a mechanism for determining whether the program has passed or failed a test.

Consider the following code:

// class that should be tested public int sum(int a, int b) {   return a + b; }  // test class static Main tester = new Main(); @Test public void testSum() {   assertEquals("2 + 3 is 5", 5, tester.sum(2, 3)); } 

The class that should be tested always returns the sum of 2 integers.
I pass as a parameter 2 and 3, and expect 5. 2 and 3 will be summed up and compared to the expected value (5). In this case the test succeeds.

How exactly can an oracle help me here? Is an oracle involved in this example?

like image 706
Evgenij Reznik Avatar asked May 07 '14 15:05

Evgenij Reznik


People also ask

What does a test oracle do?

In computing, software engineering, and software testing, a test oracle (or just oracle) is a mechanism for determining whether a test has passed or failed.

Which of the following is the best definition of a test oracle?

A test oracle is a source of information about whether the output of a program (or function or method) is correct or not.

What is testing and why it is used?

In general, testing is finding out how well something works. In terms of human beings, testing tells what level of knowledge or skill has been acquired. In computer hardware and software development, testing is used at key checkpoints in the overall process to determine whether objectives are being met.

What is meant by test oracle and test bed?

A test oracle is a source of expected results for a test case. A test oracle is a method that verifies whether software executed correctly for a test case. Test oracle is used to check the correctness of the output of the program for the test case.


1 Answers

A test oracle is a source of information about whether the output of a program (or function or method) is correct or not.

A test oracle might specify correct output for all possible input or only for specific input. It might not specify actual output values but only constraints on them.

The oracle might be

  • a program (separate from the system under test) which takes the same input and produces the same output
  • documentation that gives specific correct outputs for specific given inputs
  • a documented algorithm that a human could use to calculate correct outputs for given inputs
  • a human domain expert who can somehow look at the output and tell whether it is correct
  • or any other way of telling that output is correct.

If not vague, the concept is at least very broad.

An oracle isn't a test runner, but a test runner could use an oracle as a source of correct output to which to compare the system-under-test's output, or as a source of constraints against which to evaluate the SUT's output.

In your example, you used your personal ability to carry out the algorithm of addition as your oracle. Instead, you could use a different implementation of that algorithm as an oracle:

assertEquals("2 + 3 is 5", 2 + 3, tester.sum(2, 3)); 
like image 77
Dave Schweisguth Avatar answered Oct 03 '22 05:10

Dave Schweisguth