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

user1170330

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?

Dave Schweisguth

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));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

In Oracle SQL, what is a single pipe character ( '|' ) used for?

From Dev

What significance test is used for spearmanr in SciPy?

From Dev

What is LinkedHashMap and what is it used for?

From Dev

What port is this and what is is used for?

From Dev

What is LVM and what is it used for?

From Dev

What is localserver? What is it used for?

From Dev

What encoding is used when calling an Oracle PL/SQL procedure

From Dev

What kind of language is used to develop Oracle's Smart View

From Java

What is polymorphism, what is it for, and how is it used?

From Dev

What is the ENGINE in OpenSSL and what is it used for?

From Dev

What is @section scripts and what it is used for

From Dev

What is a ContentProvider and what is it typically used for?

From Dev

What is /boot/firmware? What is it used for?

From Dev

What is ! and : used for in REXX

From Dev

What is "with" used for in PHP?

From Dev

What is the "Public" folder used for?

From Dev

What is the @ used for in JavaScript?

From Dev

What are buildOptions and preserveCompilationContext used for?

From Dev

What is the API used by Disqus?

From Dev

What are defaulted destructors used for?

From Java

What is the python keyword "with" used for?

From Dev

What is the "pnctest" cookie used for?

From Dev

What's glUniformBlockBinding used for?

From Dev

What is JdbcDaoSupport used for?

From Dev

What is AJP protocol used for?

From Dev

What is Contenttypes used for in Django?

From Dev

What is a kernel stack used for?

From Dev

What language is used by bosun?

From Dev

What are submodules and how are they used?