In the Test Manager, the Create Test for Component workflow wizard creates an internal test harness and test case for a model or a component in the model. Components for which you can create test harnesses include subsystems, Stateflow® charts, and Model blocks. For a full list of components supported by test harnesses, see Test Harness and Model Relationship.
In the wizard, you specify:
The model to test.
The component to test, if you are not testing a whole model.
The test inputs.
The type of test to run on the component.
Whether to save test data in a MAT-file or Excel®. For more information on using Excel files in the Test Manager, see Format Test Case Data in Excel.
For an example that uses the wizard, see Create and Run a Back-to-Back Test
Note
If you are testing a component, you can select that component in the model before opening the wizard to automatically fill in the model and component fields.
If you are equivalence testing the code generated for a reusable library subsystem, before opening the Create Test for Component wizard, verify that the subsystem has defined function interfaces and that the library already has generated code. For information on reusable library subsystems, function interfaces, and generated code, see Library-Based Code Generation for Reusable Library Subsystems (Embedded Coder). You must have an Embedded Coder® license to verify generated code.
To open the Create Test for Component wizard, in the Test Manager select New > Test for Model Component.
On the first page of the wizard, click the Use current
model button to fill in the Top Model
field.
Then, if you are testing a:
Whole model, leave the Component field empty.
Single component and you selected a component in the model before
opening the wizard, click the Use currently selected model
component button to fill in the
Component field. Otherwise, enter the name of
the component.
Component in a Model Reference block, you do not need to specify the Model Reference block as the top model. Use the name of the model that contains the Model Reference block as the Top Model.
Reusable library subsystem that has a function interface, a Function Interface Settings option displays. Select the function interface for which you want to create a test.
Reusable libraries contain components and subsystems that can be shared with multiple models. You can share the code generated by the subsystems if those subsystems are at the top level of the reusable library and if they have function interfaces. Function interfaces specify the subsystem input and output block parameter settings.
To test the whole model without creating a test harness, deselect the Create Test Harness for component check box. If you are testing a specific component in the model, a test harness is created automatically, and the Create Test Harness for component option does not display.
Note
For an export-function model, the test harness creates a Test Sequence block automatically.
Click Next to go to the next page of the wizard.
On the Test Inputs page, select how to obtain the test inputs.
Use component input from the top model as test input — Simulate the model and record the inputs to the component. Then, use those inputs as the inputs to the created test harness. Use this option for debugging.
Note
If you are testing a subsystem that has function calls, you cannot obtain inputs by simulating the model because function calls cannot be logged. Use either of the other two options to obtain the inputs.
Use Design Verifier to generate test input scenarios — Create test harness inputs to meet test coverage requirements using Simulink® Design Verifier™. This option appears only if Simulink Design Verifier is installed.
Select test harness input source — Select how the inputs generated by the Design Verifier are applied to the test harness. This option appears only if you select Use Design Verifier to generate test input scenarios.
Inports
— Create a test harness
with Inport blocks as the source.
Signal Editor
— Create a test
harness with the Signal Editor as the source that contains
the input scenarios generated by the Design Verifier.
Specify inputs in the created harness — After the wizard creates the harness, open the harness in the Test Manager and manually specify the harness inputs. This option does not appear if you chose not to create a test harness.
On the Verification Strategy page, select how to test the component.
Use component under test output as baseline — Simulate the model and record the outputs from the components, which are used as the baseline.
Perform back-to-back testing — Compare the results of running the component in two different simulation modes. For each simulation, select the mode from the drop down menu. For SIL testing a reusable library subsystem, the library that contains the subsystem must already have generated code.
Define the verification logic in the created harness — After the wizard creates the harness, open the harness. Manually specify the verification logic using a Test Sequence or Test Assessments block in the generated harness. Alternatively, use logical and temporal assessments or custom criteria in the generated test case. This option does not appear if you are testing a top-level model and choose not to create a test harness.
On the Generated Test page, select the format in which to save the test data and specify the file name for the generated tests.
Specify the file format — Specify the type of file in which to save data.
Excel
— Saves the test inputs, outputs, and parameters
to one sheet in an Excel spreadsheet file. For tests with
multiple iterations, each iteration is in a separate sheet. For
more information on using Excel files in the Test Manager, see Format Test Case Data in Excel.
MAT
— Saves inputs and outputs in
separate MAT files. For tests that use Simulink
Design Verifier, the wizard saves the inputs and parameters in one
file and the outputs in a baseline file.
Specify location to save test data — Specify the
full path of the file. Alternatively, you can use the default file name
and location, which saves sltest_<model name>
in the current working folder. This option is available only for
Excel format files. MAT files are saved to the default location
specified in the model configuration settings.
Test File Location — Specify the full path where
you want to save the generated test files. Alternatively, you can use
the default file name, which is sltest_<model
name>_tests
. The file is saved in the current working
folder. This field appears only if you did not have a test file open in
the Test Manager before you opened the wizard.
If you had a test file open in the Test Manager before you opened the wizard, these options are displayed instead of Test File Location:
Add tests to the currently selected test file — The generated tests are added to the test file that was selected in the Test Browser panel of the Test Manager when you opened the wizard.
Create a new test file containing the test(s) — A new test file is created for the tests. It appears in the Test Browser panel of the Test Manager.
Click Done to generate a test harness and test case. A test harness is not created if you are testing a whole model and deselected Create a Test Harness on the first tab of the wizard.
If the model has an existing external harness, the wizard creates an external test harness for the component under test. If no harness or an internal harness exists, the wizard creates an internal test harness.
The Test Manager then opens with the test case in the Test
Browser pane and, if a test harness was created, the test harness
name in the Harness field of the System Under
Test section. The test case is named <model
name>_Harness<#>
.