Main Content

Create External Data Files to Use in Test Cases

You can create Microsoft® Excel® files, MAT-files and MATLAB® scripts to use for test case data, such as inputs, baseline data, and parameter overrides. The files use specific formats and can contain multiple types of data. See Input, Baseline, and Other Test Case Data Formats in Excel and Create a MAT-File for Test Case Inputs for information. MATLAB scripts (.m files) use MATLAB command syntax.

You can create files for input data only for tests that run in the current release. To select the current release in the Test Manager, in the System Under Test section of a test case, use Select releases for simulation.

You can add a table iteration to the test case and assign the input file to it by clicking Create in the Inputs section. Then, in the Create Input Data File dialog box, click Add iterations to run this input. After you create the input file, continue to specify the iteration. For more information on iterations, see Test Iterations.

To edit external files in the Inputs or Baseline Criteria sections, select the file and click Edit. MAT-files open in the Signal Editor. Excel files open in Excel by default, but you can also open and edit an Excel file outside of MATLAB. To edit a MATLAB script file), open the file in a text editor.

Generate an Excel File Template

You can generate an Excel spreadsheet template from a model or harness for the system under test (SUT). The generated spreadsheet extracts data from the model. You can add other data into the spreadsheet and then import it into Simulink® Test™ as a test case.

Use New > Test from Spreadsheet to open the Create Test from Spreadsheet wizard. The wizard parses the SUT for test attributes and generates a template spreadsheet and a test case with:

  • Inputs — Inputs are characterized by root input ports

  • Parameters — Named parameters in the model

  • Comparison signals — Logged signals and output ports

The wizard allows you to filter and edit the attributes needed for testing. The resulting spreadsheet has separate column sets for inputs, parameters, and comparison signals. If your test requires multiple iterations, the wizard creates a separate sheet in the same file for each iteration. You can expand the spreadsheet to add time-based signal data, tolerances, and parameter overrides. See Microsoft Excel Import, Export, and Logging Format and Input, Baseline, and Other Test Case Data Formats in Excel for a description of the format readable by Simulink Test.

Use the coordinate_transform_test model as an example for the process. Its associated Excel file, which you can open to view its formatting, is coordinate_test.xlsx.

  1. Enter openExample("coordinate_transform_test") to open the model.

  2. On the Apps tab, click Simulink Test and then, on the Tests tab, click Simulink Test Manager.

  3. In the Test Manager, select New > Test from Spreadsheet. Select Create a test template file for specifying data and follow the prompts.

  4. On the Attributes page, select which attribute categories to include in the spreadsheet. For example, if parameter overrides are not necessary for the tests, clear Parameters. The attribute categories shown on the page are derived from the SUT. If you select Comparison signals, the wizard runs the model and captures the baseline before generating the spreadsheet. Make sure the model does not run indefinitely by setting a finite stop time in Simulink.

  5. If you change the SUT during the selection process, click Refresh to synchronize the attribute lists with the SUT.

  6. If the test requires all attributes in a category as is, select Yes, include all attributes in the spreadsheet. If not, select No, I want to filter and edit the attributes. Click Next.

  7. If you are filtering the attributes, in the Parameters and Comparison tabs, clear the attributes that are not needed. For example, you can remove a logged signal from this list if it is not to be used for comparison in the tests.

    Optionally change tolerances in the Comparison page. The tolerance settings apply to all signals in the list.

    Table of signal tolerance settings

    To specify different tolerances for each signal, open and edit the spreadsheet after the wizard generates the spreadsheet..

  8. In the Scenarios page, specify the number of test scenarios and a base name for the sheets in the spreadsheet. The wizard generates each scenario as a separate sheet in the spreadsheet. The Test Manager uses each sheet as a separate iteration.

  9. In the Generated Test page, specify where to save the MLDATX test file and the XLSX spreadsheet. Click Done to generate the files.

The wizard creates two files:

  • Excel spreadsheet — The spreadsheet includes columns for inputs, parameters, and comparison signals. Inputs and comparisons have different time bases. The wizard generates an identical sheet for each test scenario. Complete the spreadsheet with specific values, such as parameter overrides, to uniquely define each scenario. See Input, Baseline, and Other Test Case Data Formats in Excel.

    Excel spreadsheet with time and parameter columns.

  • Test file — The test case imports the Excel spreadsheet. The fields in the spreadsheet are locked to the spreadsheet, and cannot be edited in the Test Manager.

The resulting test case in the Test Manager has the Create Test Case from External File option selected. The Parameter Overrides and Baseline Criteria sections include data from the file.

Create test from external file option and parameter overrides table

Baseline criteria table

To change the locked fields, edit the spreadsheet outside MATLAB. If you change one or more parameters, capture the baseline again by clicking Capture in the Baseline Criteria section.

Input, Baseline, and Other Test Case Data Formats in Excel

As an alternative or in addition to using the wizard, you can specify signal data and time data associated with the signal in a Microsoft Excel file to use as input to your test case or as baseline criteria. To support a range of models and configurations, you can specify signal data of most data types. You can indicate whether signals are scalar, multidimensional, or complex. You can optionally specify the data type, block path and port index, units, interpolation type, and function-call execution times. You can also specify values for parameter overrides. If your Excel file has more than one sheet, the data on each sheet is used in the Test Manager as a separate iteration.

For general information on how to format data in Excel files, see Microsoft Excel Import, Export, and Logging Format. For information on how to use Excel and other external files, see Use External File Data in Test Cases.

Inputs Format

To create an Excel file and view the format for model input data, click Create in the Inputs section of a test case in the Test Manager. Then, set Excel as the File format. The input data includes a time column and a column of data values for each model inport. See the example spreadsheet in Multiple Runs.

To use an existing Excel file for the model input data, click Add.

Baseline Data Format

To view the Excel format for the baseline data, capture the baseline from your model. If you do not already have an Excel file open, click Capture in the Baseline Criteria section of a test case in the Test Manager. Then, select Excel as the File format. The Excel file includes the time and associated value for each signal in the model that is marked for logging. Information about the logged signal includes the signal name, absolute tolerance, path of the block from which the signal originates, the port index of the block, and the source type.

Excel file for baseline capture showing time and multiple output signal data columns

This sample baseline spreadsheet includes uniquely named signals and signal block paths. Causes of signals not being well defined are:

  • When a signal does not have a name in the model, a name is automatically assigned to it in the spreadsheet.

  • When you manually create a spreadsheet and do not include the signal name, a signal name with the format block_name: port_index is assigned to the signal.

  • When the signal name included in a spreadsheet does not uniquely identify the signal, add the block path for that signal. For example, signals with the same names at different levels in the model hierarchy are not uniquely identified if you only specify the name. If you do not include the block path, the first signal with that name is used.

You can include both baseline (Source:Output) data and input (Source:Input) data in the same Excel file. See the example spreadsheet in Multiple Runs.

To use a manually created Excel file as expected outputs, click Add in the Baseline Criteria section of the test case in the Test Manager and specify the file name.

Parameter Overrides Format

The parameters in a spreadsheet are in two columns labeled Parameter, which is the parameter name, and Value, which is the parameter value. See the example spreadsheet in Multiple Runs. To override a parameter, change its value in the spreadsheet before you add the file to the test case.

For parameter types such as Simulink.Parameter, Simulink.DataDictionary, or Simulink.LookupTable objects, you can specify only the values to override. The values you do not specify use the values set in the model. The Excel format for overriding these parameters is:

Format for Simulink parameter

To use parameter overrides from an Excel file, click Add > Add File in the Parameter Overrides section of a test case in the Test Manager.

Create a MAT-File for Test Case Inputs

You cannot manually create a MAT file to use in a test case. Follow these steps to generate a MAT file.

  1. In the test case, under System Under Test, specify the model whose input data you want to create a MAT-file for.

  2. In the Inputs section of the test case, click Create.

  3. In the dialog box, set File Format to MAT. Specify the location for the MAT-file and click Create.

    The Signal Editor opens.

  4. In the left pane of the Signal Editor, expand the data node. Then select the signal whose data you want to add.

  5. Specify the signal data. In the bottom pane, select the data type from the list, and enter the time and signal data for the signal.

    Signal editor with inputs options.

  6. To update your signal data, click Apply.

  7. After adding the signal data, click Save.

MATLAB Script Format for Test Case Data

You can use MATLAB scripts to specify test case data. The files include MATLAB language commands formatted in the same way as code you write at the command line. For example, a MATLAB script file that sets two parameter values contains this code:

a_min = 1.3;
a_max = 22.4;
To add these parameters from the file to your test case, use Add > Add File in the Test Manager Parameter Overrides section.

See Also

|

Related Topics