So let's start our lesson on white docs testing by considering again the
program PrintSum. If you remember, this is the same program that we used when
we were talking about black box testing. It's the program that takes two
integers, A and B, and produces, as a result, the sum of the two.
And when we were looking at this problem in the context of black
box testing, we did not look at
implementation. But that's exactly what we're going to
do now. So we're going to open the box and look at how the
code is implemented. And as you can see, the programmer was kind of creative.
Because instead of just adding the two numbers and printing them, he
or she also decided to print them in a specific color depending
on whether they were positive numbers or negative numbers. So positive results
are printed in red and negative results are printed in blue. And as
you can see by looking at the code we can see some
interesting cases that we might want to test. For instance you can
see that there are two decisions made here. So we might decide
that this is an interesting case and therefore we want to test it.
Similarly we might look at this other case and we might
also decide that this is another interesting case and therefore we
want to test this one as well. So let's discuss this
in a slightly more formal way by introducing the concept of
coverage criteria which are really the essence of why box testing.
First of all coverage criteria are defined in terms of test
requirements where test requirements are the elements, the entities in the
code that we need to exercise. That we need to execute
in order to satisfy the criteria. And we'll see plenty
of examples of that. And normally, when I apply a coverage
criterion, my result is a set of test specifications. And we
already saw test specifications. Those
are basically descriptions, specifications, of how
the tests should be in order to satisfy the requirements. And
they also result in actual test cases, which are instantiations of
the test specifications. And again this is exactly analogous to what
we saw when we were talking about the black box testing.
So let's see what this means by going back to our
example. A minute ago, we looked at the print sum code
and we identified two interesting cases for our code. And those
are exactly our test requirements. So we have a first test
requirement here, which is the execution of this particular statement and
a second requirement here and this one corresponds to the execution
of this other statement. So for this example there are two
things that we need to do in order to satisfy our
coverage requirements. Execute this statement and execute this statement.