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.
Because each stub data table maps to a particular method in your stub script,
a separate stub data table is created for each stub method. As you work with
the stub script, the stub data table view is automatically updated when you
move the cursor from one method to another. When you first open your stub
script, no stub data table is displayed until you move the cursor to a method
in the stub script.
Note: For the stub data table and stub script to synchronize
as expected, make sure that the option is enabled.
The following screen capture shows an example of a stub data table.
The stub data table provides
content assist which automatically
completes content when you press
Ctrl+Space. It also
automatically validates syntax and data type to guarantee that the data you
enter is syntactically correct.
Note: Syntax validation is turned off automatically
if a stub cannot compile.
With stub data tables you can perform the following tasks in the same way
as for test data tables:
- Supply stub data in the form of expressions, sets, ranges and datapools
- Add elements to an array
- Supply stub data for the attributes of object data types
- Partition your data into data sets (equivalence classes)
- Cut, copy and paste compatible content between data sets
- Specify breakpoints in data sets
In many ways stub data tables are very similar to test data tables, but
there are several differences.
- Inputs and outputs: With test data tables, you define the input and expected
output values that drive the test. With stub data tables, you define the actual
output values that are the result of particular input values. As a result,
you can use stub data tables to drive predictable behavior on the part of
the stub.
- Sets, ranges and datapools: With test data tables, you can use sets, ranges,
and datapools for the input values, expected output values, and return values.
With stub data tables, you can use sets, ranges, and datapools only for input
values.
- Exceptions: In test data tables, you specify the type of an exception,
such as "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, such as "new java.lang.RuntimeException("Exception"),
not just the type of the expression.