The purpose of a stub data table is to supply stub routines with
data. Stub data tables define the output behavior of a stubbed method in response
to certain inputs. With the stub data table, you simulate the stubbed class
by specifying the actual input and return values for each stubbed method.
In many ways stub data tables are very similar to test data tables, but
there are several differences.
- Inputs and outputs. Whereas test data tables define the input and expected
output values that drive the test, stub data tables define the actual output
values that are the result of particular input values. As such, stub data
tables can be used to drive predictable behavior on the part of the stub.
- Sets and ranges. With test data tables, sets and ranges can be used for
the input values, expected output values, and return values. With stub data
tables, sets and ranges can only be used for input values.
- Exceptions. In test data tables, you specify the type of an exception,
for example "java.lang.RuntimeException", to check that the test will throw
an exception of that type. In stub data tables, you specify a behavior that
will throw an exception by writing the actual expression, not just the type
of the expression, for example "new java.lang.RuntimeException("Outchhhh").