MATLAB Examples

Clone and Export a Test Harness to a Separate Model

This example demonstrates cloning an existing test harness and exporting the cloned harness to a separate model. This can be useful if you want to create a copy of a test harness as a separate model, but leave the test harness associated with the model component.


High-level Workflow

  1. If you don't know the exact properties of the test harness you want to clone, get them using sltest.harness.find. You need the harness owner ID and the harness name.
  2. Clone the test harness using sltest.harness.clone.
  3. Export the test harness to a separate model using sltest.harness.export. Note that there is no association between the exported model and the original model. The exported model stands alone.

Open the Model and Save a Local Copy

model = 'sltestTestSequenceExample';

Save the local copy in a writable location on the MATLAB path.

Get the Properties of the Source Test Harness

properties = sltest.harness.find([model '/shift_controller'])
properties = 

  struct with fields:

                  model: 'sltestTestSequenceExample'
                   name: 'controller_harness'
            description: ''
                   type: 'Testing'
            ownerHandle: 12.0005
          ownerFullPath: 'sltestTestSequenceExample/shift_controller'
              ownerType: 'Simulink.SubSystem'
                 isOpen: 0
            canBeOpened: 1
               lockMode: 0
       verificationMode: 0
         saveExternally: 0
          rebuildOnOpen: 0
       rebuildModelData: 0
    postRebuildCallback: ''
              graphical: 0
                origSrc: 'Test Sequence'
               origSink: 'Test Assessment'
    synchronizationMode: 0

Clone the Test Harness

Clone the test harness using sltest.harness.clone, the ownerFullPath and the name fields of the harness properties structure.


Save the Model

Before exporting the harness, save changes to the model.


Export the Test Harness to a Separate Model

Export the test harness using sltest.harness.export. The exported model name is ControllerTestModel.

sltest.harness.export([model '/shift_controller'],'ControllerHarness2',...