Main Content

addSpecifiedFault

Class: sltest.testmanager.FaultSet
Namespace: sltest.testmanager

Add fault to fault set in test case

Since R2024a

Syntax

specifiedFault = addSpecifiedFault(fs,modelElement,faultName)

Description

specifiedFault = addSpecifiedFault(fs,modelElement,faultName) adds the fault faultName on the model element modelElement to the fault set fs. You can only add a fault to a fault set once. You must have Simulink® Test™ to use this method.

Input Arguments

expand all

Fault set, specified as a sltest.testmanager.FaultSet object.

Path of the model element, specified as a string scalar or character vector. In Simulink models, this argument is the path to a block output or input port. In Simscape™ blocks, this argument is the path to a fault-capable model subelement. In System Composer™ models, this argument is the path to a component output or input port.

Data Types: char | string

Name of the fault, specified as a string scalar or character vector.

Data Types: char | string

Output Arguments

expand all

Fault added to the fault set, returned as a sltest.testmanager.SpecifiedFault object.

Examples

expand all

Suppose you have a test file named myTestFile that contains one test case. The test uses myModel as the model under test, and the model contains a fault named myFault on the output port of a Sine Wave block. Create a test case and fault set, and add the fault to the fault set.

tf = sltest.testmanager.TestFile("myTestFile.mldatx");
ts = sltest.testmanager.TestSuite(tf,"myTestSuite");
tc = sltest.testmanager.TestCase(ts,"simulation","myTestCase");
faultSet = addFaultSet(tc);
sltest.testmanager.refreshFaults("myModel")
testFault = addSpecifiedFault(faultSet,...
  "myModel/Sine Wave/Outport/1","myFault")

Tips

  • If you add faults to the model under test after you add fault sets to test cases, use the sltest.testmanager.refreshFaults function to make the faults available to the fault set.

Version History

Introduced in R2024a