Create an External Data Unit Test

This section describes how to create a unit test that accepts input and/or validations from a CSV file (file extension .csv). You can create a unit test once and then provide a data file containing different input or validations to run iterations of the test. The wizard creates a unit test file that accepts data from the CSV file.

The following topics are covered:

Note:
Similar to other unit tests, external data unit tests can be run from the unit test Ant script. For information, see Creating Ant Scripts to Run Unit Tests.


Create the Unit Test

Start of instruction setTo create an external data unit test

  1. Select Testing > Create External Data Unit Test for a project in the Project Explorer view.

    Or:
    Select Testing-Suites > Create External Data Unit Test in the Project Explorer view.

    Or:
    Select Testing-Suites> SubfolderName > Create External Data Unit Test in the Project Explorer view.

    The Define External Data Unit Test Details panel is displayed. For example:

    graphics/define-external-data-settings.png

    Using this panel, you can:

    Task Procedure
    Change the name of the project in which to create the external data unit test. Type the name of the Natural project in Project or select Browse to display a window listing the existing projects for selection.

    Note:
    The project must currently exist.

    Provide the name(s) of a subfolder(s) in which to save the external data unit test. If the folder does not currently exist, it will be created for you. Type the name of the folder in Parent suite or select Browse to display a window listing the available folders for selection.

    By default, the unit test is stored in the Testing-Suites folder in the current project. If you specify a suite folder name, it becomes a subfolder in the Testing-Suites folder and the unit test will be stored in that folder.

  2. Type the name of the external data unit test in Test name.

  3. Select an existing business service or Natural unit test in the Source unit test details section.

    The selected unit test will be executed for each row in the data file. To display the available unit test files for selection, select Browse for Use existing test. Optionally you can create a new business service or Natural unit test. For information, see Create a New Unit Test.

  4. Select an existing data file in the Source data file (CSV) details section.

    To display the available CSV data files for selection, select Browse for Use existing file. Optionally you can create a new data file. For information, see Create a New Data File.

    Note:
    A wizard is available to record the sample data used to test a business service or subprogram directly and then export the data to a CSV file. For information, see Export Test Data to a CSV File.

  5. Select Finish.

    The external data unit test file is generated into the Testing-Suites folder (or subfolder) and listed in the Project Explorer view.

    The .exttst file is also displayed in the editor view.

    Note:
    The .csv file and/or the .nattst/.bsrvtst files may also be created.

  6. Define the configuration settings for the unit test in the editor view.

    For information, see Configure Column Mappings and Sample Data.

  7. Select the Connection tab and define the connection settings for the unit test.

    For information, see Define Connections.

  8. Save the settings.

Create a New Unit Test

Start of instruction setTo create a new unit test

  1. Select Create new test in the Source details section on the Define External Data Unit Test Details panel.

  2. Select Next.

    The Define New Unit Test Details panel is displayed. For example:

    graphics/define-new-unit-test-details.png

  3. Type the name of the unit test in New test name.

  4. Select the object type for the source unit test in Object type.

    You can select either Subprogram (the default) or Business service. When Business service is selected, an additional field is added to the panel. For example:

    graphics/define-new-unit-test-details-bs.png

  5. Select Browse in Object path.

    A list of available business service or subprogram unit test files is displayed. Select the unit test to use for the external data unit test and select OK.

  6. For a business service unit test, select the method to test in Object method.

  7. Select Finish to create the external data unit test and new unit test.

    Or:
    Select Next to create a new data file.

    Note:
    This option is only available when Create new file is selected on the Define External Data Unit Test Details panel.

Create a New Data File

Start of instruction setTo create a new data file

  1. Select Create new file in the Source data file (CSV) details section on the Define External Data Unit Test Details panel.

  2. Select Next.

    The Define New Data File Details panel is displayed. For example:

    graphics/define-new-data-file-details.png

    Note:
    If Create new test on the Define External Data Unit Test Details panel is also selected, the Define New Unit Test Details panel is displayed before this panel.

  3. Type the name of the data file in New data file name.

    Using this panel, you can:

    Task Procedure
    Change the character used to separate entries in the first row of the CSV file. Type a new character in Delimiter.
    Reserve the first row in the CSV file for the field names. Select First row contains field names. At runtime, the first row in the CSV file is reserved for field names.

    Note:
    When selecting fields for the first row in a CSV file, you cannot specify the number of occurrences of an array to include. By default, a maximum of five occurrences of each array will be included. To add and/or remove occurrences from the generated CSV file, you must edit the file manually.

    Display fields that can be selected for the first row of the CSV file. Select Expand All. To close the tree view, select Collapse All.
    Select fields to be included in the first row of the CSV file. Select Select All and then deselect the fields you do not want to include in the CSV file. To deselect all fields, select Deselect All.
  4. Select Finish to create the external data unit test, a new data file, and optionally, a new unit test.

Configure Column Mappings and Sample Data

This section describes how to map columns in the CSV file (file extension .csv) to fields in the PDA used by the business service or subprogram unit test. The following CSV file was used for examples:

#FUNCTION,INPUT-DATA.#FIRST-NUM,INPUT-DATA.#SECOND-NUM,INPUT-DATA.#SUCCESS-CRITERIA,OUTPUT-DATA.#RESULT,OUTPUT-DATA.#SUCCESS
Add,1,2,3,3,FALSE
Add,1,9,10,10,TRUE

Start of instruction setTo configure column mappings and sample data

  1. Select the Configuration tab in the editor for the external data unit test.

    For example:

    graphics/exttst-file-in-editor-configuration-tab.png

  2. Select Add in the Column Mappings section.

    The Edit Mapping window is displayed. For example:

    graphics/add-column-mapping-window.png

    The number of the first unmapped column is displayed in Column number. You can change this number to define the mapping for another column.

  3. Select the name of the field to use for this column in Field name.

  4. Type the index position in Index (used when the field is an array).

  5. Select the type of validator to use for the field in Validator.

    The type of validator to use depends on the type of data in the field. The available validators are:

    • BooleanValidator

    • ByteValidator

    • ComparisonValidator (displays a combo box with the options: ">", "<", "=", "<=", ">=")

    • DateValidator

    • DecimalValidator

    • IntegerValidator

    • RegexValidator (creates regular expressions to validate the contents of a field)

    • StringValidator

    • TimeValidator

  6. Select OK.

    The new column mapping is added to the list of mappings on the Configuration tab.

  7. Continue adding column mappings until all columns used for the test have been added.

    • To revise a mapping, select the mapping in Column Mappings and select Edit. The Edit Mapping window is displayed to change the mapping.

    • To remove a mapping, select the mapping in Column Mappings and select Delete. The mapping is removed from Column Mappings.

    Optionally, you can use the Configuration tab to:

    Task Procedure
    Change the name and/or location of the unit test file used for the external data unit test. Type the name of the unit test in Unit test file or select Browse to display a window listing the existing unit test files for selection.

    Note:
    The unit test must currently exist.

    Change the name and/or location of the CSV file containing field names and input for the external data unit test. Type the name of the CSV file in Data file or select Browse to display a window listing the existing CSV files for selection.

    Note:
    The CSV file must currently exist.

    Reserve the first row in the CSV file for the field names. Select First row contains field names. At runtime, the first row in the CSV file is reserved for field names.

    Note:
    When selecting fields for the first row in a CSV file, you cannot specify the number of occurrences of an array to include. By default, a maximum of five occurrences of each array will be included. To add and/or remove occurrences from the generated CSV file, you must edit the file manually.

    Change the delimiter character used to separate columns in the CSV file. Type a new delimiter character in Column delimiter.
    Retrieve sample data from the CSV file. Select Refresh in the Sample Data section. The first 20 rows in the CSV file are retrieved.

    Tip:
    To apply changes to the external data file to the unit test, use this option with the Map option.

    Map new sample data to the columns. Select Map (enabled when the First row contains field names option is selected). A confirmation window is displayed, indicating that all current column mappings will be removed. Select Yes to delete the old mappings and apply the new mappings.
  8. Save the configuration settings.