Main Content

Create Multiple Baseline Tests in Batch Mode

This example shows how to create baseline test cases and test harnesses for multiple components in batch mode using sltest.testmanager.createTestForComponent. The example also includes report generation.

Load the Model

load_system("sltestCruiseControl")

Customize the Test Harness Names

To improve traceability of testing artifacts, such as test case and test harness names, customize the default names of the harnesses to be created so the names use the component name instead of the owning model name.

sltest.harness.setHarnessCreateDefaults...
    ("Name","$Component$_Harness");

Create the Test Cases and Test Harnesses in Batch Mode

Use the sltest.testmanager.createTestForComponent API to create multiple test cases and test harnesses at the same time. Specify to create a test file and the test filename, the top model, components to test, and the test type.

[tc,status] = ...
  sltest.testmanager.createTestForComponent(...
    "CreateTestFile",true,...
    "TestFile","batchBaselines.mldatx",...
    "TopModel","sltestCruiseControl",...
    "Component",[...
      "sltestCruiseControl/TargetSpeedThrottle",...
      "sltestCruiseControlMode/disableCaseDetection",...
      "sltestCruiseControl/DriverSwRequest",...
      "sltestCruiseControl"],...
    "CreateExcelFile",true);

Test Execution

The createTestForComponent API generates the test file and test harnesses in the current working directory. Save the harnesses attached to the model, and save the test file.

tf = sltest.testmanager.TestFile("batchBaselines.mldatx");
tf.saveToFile;

Run the tests and export and save the test results. Open the test manager to view the created test cases and results plots.

resultSet = tf.run;
sltest.testmanager.exportResults(resultSet,...
    "batchBaselinesResults.mldatx");
sltestmgr;

Generate a Results Report

sltest.testmanager.report(...
    resultSet,"myTestResultsReport.zip",...
    "IncludeCoverageResult",true,...
    "IncludeSimulationSignalPlots",true,...
    "IncludeComparisonSignalPlots",true,...
    "IncludeTestResults",0,...
    "IncludeSimulationMetadata",true);

Clean Up

bdclose({"sltestCruiseControl",...
   "sltestDriverSwRequest",...
   "sltestCruiseControlMode"})
sltest.testmanager.clear
sltest.testmanager.clearResults
sltest.testmanager.close

See Also