You can run test cases using data defined in external MAT-files or Microsoft® Excel® files. You can map the data to your model (system under test [SUT]) using these mapping modes:
The names of the inport block the signal data corresponds to
The full block path name, that is, in the form
system/block
The name of the signal associated with the inport block
Port number, that is, sequential port numbers of the inport blocks, starting at 1
You can add multiple external input files to a test case. After you add the files, select the one you want to use in the test case from the External Inputs table. If you are using test iterations, you can assign one input file to each iteration.
For more information about how Simulink® handles inport mapping, see Map Root Inport Signal Data.
When you map external inputs to model elements, the mapping can create these possible results. These results appear under Inputs in the Test Manager interface in the Status column:
Mapped — The mapping succeeded and no further action is needed.
Failed — The mapping failed. Click the Failed link for more information.
Warning — The mapping occurred with warnings. Click the Warning link to see whether you need to address them
Stale — This status can occur when you update your external inputs in Test Manager. A stale state occurs if you did not map the new inputs. To address this status, click the Status link, which opens the Add Input dialog box. Click Map Inputs to map the new input data and then click Add.
You can create a test case in Test Manager using the Create Test from Spreadsheet wizard. From Simulink Test Manager, select New > Test from Spreadsheet. Select Use existing test data from a spreadsheet and follow the prompts. You can use the following spreadsheet and model as an example:
<matlabroot>\examples\simulinktest\data\coordinate_tests.xlsx <matlabroot>\examples\simulinktest\main\coordinate_tests.slx
In the Attributes page, make sure all attribute categories that exist in the spreadsheet are displayed. Click Validate to map each input to the model by block name. If necessary, change the spreadsheet and/or SUT and click Refresh and validate again. After a successful validation, save the test.
The test case imports the spreadsheet. The fields defined in the spreadsheet are locked to the spreadsheet, and cannot be edited in the Test Manager.
Note
If you cannot see all the data in a column, click + in the upper right corner to hide other columns and resize the desired column.
To change the locked fields, edit the spreadsheet outside of MATLAB®.
For multi-dimensional signals, each dimension is represented in a separate column in the spreadsheet. By default, only the dimensions with non-zero values are included. If all dimensions have zero value, then only the last dimension is included in the spreadsheet.
If you have a test case and want to add test data to it from Excel spreadsheet, you must associate it with the spreadsheet:
Open the test case.
Check the Create Test Case from External File option.
Browse for the spreadsheet with the test data.
The input, parameter, and comparison signal data in the spreadsheet overrides the data in the test case. The fields defined in the spreadsheet are locked to the spreadsheet. To edit, do one of the following:
Edit the spreadsheet outside of MATLAB and click Refresh for the File field.
Clear the Create Test Case from External File option and edit the test case in the Test Manager. Selecting this option again causes values in the spreadsheet to overwrite the values in the test.
You can import Microsoft Excel spreadsheets to use as inputs. You can import multiple sheets at once and specify a range of data. Selecting sheets and specifying ranges is useful when each sheet contains a different data set or the same file contains input data and expected outputs.
For information about the Excel file format, see Format Test Case Data in Excel.
In the test case, expand the Inputs section and click Add.
Browse to your Microsoft Excel file and click Add.
Select each sheet that contains input data. You can specify a range of data.
If you want to use each sheet to create an input set in the table, select Create scenarios from each sheet.
Under Input Mapping, select a mapping mode.
Click Map Inputs. The Mapping Status table shows the port and signal mapping.
For more information about troubleshooting the mapping, see Understand Mapping Results.
Click Add.
In the test case, expand the Inputs section and click Include input data in test result.
Under the External Inputs table, click Add.
In the Add Input dialog box, specify the Excel file name and the mapping mode, which specifies how to map the Excel data to root-level Inport blocks in the model.
Click Map Inputs. The Mapping Status table shows the port and signal mapping.
Click Add.
See Importing Test Data from Microsoft® Excel® for a complete example.
In the test case, expand the Inputs section and click Add.
Browse to the MAT-file and click Add.
Under Input Mapping, choose a mapping mode.
Click Map Inputs. The Mapping Status table shows the port and signal mapping.
For information about troubleshooting the mapping status, see Understand Mapping Results.
Click Add.