Skip to Main Content Skip to Search
Product Documentation

Working with Test Cases and Signals Programmatically

Test Case Editor API

The functionality of the Test Case Editor, as described in this chapter, is also available via a command-line interface. The functions allow you to do the following tasks programmatically:

For information on usage and syntax of the functions, see these reference pages.

The objects:

The saving and loading functions:

The signal manipulation functions:

Loading and Saving Test Cases

If you have a test with test cases you can load and save them programmatically. The test cases can be created using the Test Case Editor, as described in this chapter, or they can be created with the automatic test harness generation feature. A test can be generated automatically from Simulink (see Generating the Test Harness from Simulink), or via the command line (see Generating the Test Harness at the MATLAB Command Line).

In this example workflow, we will generate a test automatically, then load the test cases, modify them, then save the test cases.

  1. Create a SystemTest test called myTest.test from the command line based on the model myModel.

    systest.createHarness('myModel', 'C:\Work\myTest.test'); 

    The test is created and put into your C:\Work folder.

  2. As part of the test generation, one or more test cases are created with signal names corresponding to the Inport blocks in your model. You can now access the test case(s) programmatically.

    Load the test cases contained in the test myTest.test.

    testCases = stLoadTestCases ('myTest.test');
  3. You can now modify the test cases, using the functions listed in Test Case Editor API. For example, you could add and/or modify signals contained in the test case(s).

  4. After you have finished working with the test case(s), you can save them back to the test.

    stSaveTestCases('myTest.test', testCases);
  5. Load the test in the SystemTest desktop.

    systemtest('myTest.test')

Editing Test Cases

You can add test cases, signals, and segments to a test and configure and edit existing test cases, signals, and segments in a test.

signal = systest.signals.Signal(segment_type) creates a signal with a segment of type segment_type.

For a list of supported segment types and their properties, see the reference page for the systest.signals.segments function.

The following is an example workflow of editing existing test cases. In this case we load the test case, add a signal to it, then save the test case.

  1. Load the test cases contained in the test myTest.test.

    testCases = stLoadTestCases ('myTest.test');
  2. Create a ramp segment with an Offset of 2 and a FinalValue of 6.

     segment = systest.signals.segments.Ramp('Offset', 2, 'FinalValue', 6)
  3. Update the first test case's signal MySignal to use the new segment.

     testCases(1).MySignal.Segments = segment;
  4. After you have worked with the test case(s), you can save them back to the test.

    stSaveTestCases('myTest.test', testCases);

Creating Signals

You can create signals with default properties or create them and specify properties. You can create the following signal/segment types:

For a list of the properties for each segment type, see the reference page for the systest.signals.segments package.

If you add a segment and do not specify any properties, it is created with default properties. Default properties of the signals are defined in The Signal Types. To add properties, follow the syntax shown in the examples below.

Creating Signals with Default Values

Create a signal with one segment using default values, in this case a constant.

systest.signals.Signal('Constant')

Create a Signal with two segments using default values, in this case a constant segment followed by a step.

systest.signals.Signal('Constant', 'Step')

Creating Signals with Properties

Create a segment with one property, in this case a Constant segment with a Value of 5 .

 segment = systest.signals.segments.Constant('Value', 5)

Create a segment with multiple properties, in this case a ramp segment with an Offset of 2 and a FinalValue of 10.

 segment = systest.signals.segments.Ramp('Offset', 2, 'FinalValue', 10)

Appending Segments to Signals

If you create segments, you need to append them to signals. The following is an example of creating a signal, creating segments, then adding the segments to the signal.

Create a signal with one segment.

 signal = systest.signals.Signal('Step');

Create two stand-alone segments.

 ramp = systest.signals.segments.Ramp();
 pulse = systest.signals.segments.Pulse();

Add the two segments to the end of the signal's Segments property, which is an array of segment objects.

 signal.Segments = [signal.Segments ramp pulse]

Importing Data from an External Source into a Test Case

You can use the programmatic interface to import test cases from external sources, such as an Excel file, a Simulink Signal Builder harness, or a Simulink Design Verifier data file.

The following is an example of the basic high-level workflow of importing data from an external source. To see the details of this example, see the demo "Importing Test Cases from Excel into a Test Harness" by opening the SystemTest Help, then Demos > Programmatic Interface > Importing Test Cases from Excel into a Harness.

  1. Start with a model. In the case of this demo, the model contains an Inport block with a bus that contains four signals.

  2. The demo imports a test case from a single worksheet in an Excel file using the function xlsread. It also assigns the data in the columns to signals in the test case.

  3. Create a test case using the systest.TestCase function.

  4. Create signals from the data in the spreadsheet columns using the systest.signals.Signal function.

  5. Create a SystemTest test file using the systest.createHarness function.

  6. Then append the test case to the newly created test using the stLoadTestCases and stSaveTestCases functions.

To see the specific commands for these steps, see the above referenced demo in the SystemTest Help.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS