Reputation: 1962
This might be a pretty naive question for most of you, but I am kind of confused by it.
when we have to design a test case for some program, how do we know what is the expected value/outcome. The program might do some complex calculations and use complex algorithms to compute its final output which may not be possible to compute by other means. Even if we were to compute on that same input using other means and then use the output value by that mean as an expected value to test our original program, then how can we be sure that the expected value that was computed from a different program/mean was correct, to be sure that program also has to be tested, and so we are back to square one.
Upvotes: 0
Views: 520
Reputation: 61
Your question gets at the hardest problem in software testing, known as the "oracle" problem.
To support testing, we'd like to have a trusted source of expected results for any test input. In most testing scenarios, this essentially means that we have the equivalent of a perfect, bug-free implementation of the system under test. Of course, if we had that, we could probably skip developing the SUT and its testing.
But that usually isn't the case. So, there are many practical (and some exotic) strategies for producing the expected results for test cases. This can be as simple as using a spreadsheet to compute functions, picking some queries that have know results, or comparing the output of existing equivalent or similar system to output of the system under test.
Chapter 18 of my book, Testing Object-Oriented Systems, provides 16 test design patterns for oracles, most of which can be automated.
This page gives a summary of the book and links to Amazon http://www.robertvbinder.com/home/thought-leadership/books/
Bob
Upvotes: 1
Reputation: 11717
Your question doesn't really make sense.
Testing is the activity of treating the system-under-test as a black box. What you ask the system (in your case: the calculation) is basically this: Ok, when I feed the method with these values, then I want it to return this value.
There simply is no other way than knowing in advance what should be the result of an operation. It may be a lot of work in some cases, but everything else would be logically inconsistent, and it would test only the fact that the test author knows how to use the testing framework...
Upvotes: 1
Reputation: 26157
If a calculation is to too complex to figure it out on paper with a calculator, then how would you even be able to program it? Even if the calculation has to be done in small steps, you can write several different test cases on paper and test that step of the calculation in the program, and work your way through it. A computer can only do what a human tells it to do.
Upvotes: 2