A test table is used to perform unit tests on executable tables, such as decision tables and method tables. It calls a particular method, provides test input values, and checks whether the returned value matches the expected value. Test tables are mostly used for testing decision tables.
Note: Test tables can be used to execute any Java method but in that case a method table must be used as a proxy.
For example, in the following diagram, the table on the left is a decision table but the table on the right is a unit test table that tests data of the decision table:
Figure 25: Decision table and its unit test table
A test table has the following structure:
The first row is the table header, which has the following format:
Testmethod <method name> <test table name>
'Testmethod' is a keyword that identifies a test table. The second parameter is the name of the decision table method or any other Java method to be tested. The third parameter is the name of the test table, which is also the name of the method by which the test table can be executed from Java code.
The second row provides a separate cell for each input parameter of the decision table method followed by column _res_, which typically contains the expected test result values.
The third row contains display values intended for business users.
Starting with the fourth row, each row is an individual test run.
When a test table is called, the OpenL Tablets engine calls the specified method for every row in the test table and passes the corresponding input parameters to it.
Application run-time context values are defined in the run-time environment. Test tables for overloaded tables must provide values for the run-time context significant for the tested table. Run-time context values are accessed in the test table through the _context_ prefix. An example of a test table with the context value Lob follows:
Figure 26: An example of a test table with a context value
User can use the _erorr_ column of Testmethod table to test algorithm where error function is used. OpenL engine compares error message and value of _error_ column to decide is test passed or not.
Figure 27: An example of a test table with a expected error column
Test results can be accessed through the test table API. For example, the following code fragment executes all test runs in a test table called insuranceTest and displays the number of failed test runs:
TableWrapper tableWrapper = new TableWrapper();
TestResult tr = tableWrapper.insuranceTestTestAll();
System.out.println("Number of failed test runs: "+tr.getNumberOfFailures());
If OpenL Tablets projects are accessed and modified through OpenL Web Studio, the user interface provides more advanced and convenient utilities for running tests and viewing test results. For information on using OpenL Web Studio, see OpenL Web Studio User's Guide.