Data-Driven Unit Tests

Data-driven tests are a type of test suited to testing data where values read from a source are passed through the same tests.

The Micro Focus Unit Testing Framework supports data-driven tests when connecting to data sources in comma separated values (CSV) format.

You can incorporate a data source into your traditional unit tests by specifying a data source descriptor, MFU-MD-TESTDATA, in the metadata entry point; for example:

ENTRY "MFUM_MYTESTCASE".
   move "csv:MyCSVSource.csv" to MFU-MD-TESTDATA.
When the test case is executed, it runs once for each row of selected data within the data source. It is possible to control which rows are tested by using a filtering condition to select rows based on one of its column values, by using the MFU-MD-DD-CSV-FILT-COND metadata; for example:
move "Surname = Jones" to MFU-MD-DD-CSV-FILT-COND
You can also selectively run the test case against a single row within the source if you are using the -csv-line-filter option from the command line test runner syntax.

To use the data in your test cases, you define external COBOL items in the Working Storage that correspond to the column headers; for example, to define and use data in a column titled EarnedPoints, define the COBOL item as such:

01 mfu-dd-EarnedPoints is MFU-DD-VALUE external.

You can then use the item in your source code as you would any other data item.

Refer to the Examples - Writing Tests section for a working example of a data-driven test.