Список функций и объектов в программном интерфейсе Simulink ® Test™ см. в разделе Тестовые сценарии.
В этом примере показано, как использовать sltest.testmanager функции, классы и методы автоматизации тестов и создания отчетов. Можно создать тестовый случай, отредактировать критерии тестового случая, выполнить тестовый случай, экспортировать выходные данные моделирования и программно создавать отчеты о результатах. В примере сравниваются выходные данные моделирования модели с базовой линией.
% Create the test file, test suite, and test case structure tf = sltest.testmanager.TestFile('API Test File'); ts = createTestSuite(tf,'API Test Suite'); tc = createTestCase(ts,'baseline','Baseline API Test Case'); % Remove the default test suite tsDel = getTestSuiteByName(tf,'New Test Suite 1'); remove(tsDel); % Assign the system under test to the test case setProperty(tc,'Model','sldemo_absbrake'); % Capture the baseline criteria baseline = captureBaselineCriteria(tc,'baseline_API.mat',true); % Test a new model parameter by overriding it in the test case % parameter set ps = addParameterSet(tc,'Name','API Parameter Set'); po = addParameterOverride(ps,'m',55); % Set the baseline criteria tolerance for one signal sc = getSignalCriteria(baseline); sc(1).AbsTol = 9; % Run the test case and return an object with results data ResultsObj = run(tc); % Get the test case result and the Sim Output run dataset tcr = getTestCaseResults(ResultsObj); runDataset = getOutputRuns(tcr); % Open the Test Manager so you can view the simulation % output and comparison data sltest.testmanager.view; % Generate a report from the results data filePath = 'test_report.pdf'; sltest.testmanager.report(ResultsObj,filePath,... 'Author','Test Engineer',... 'IncludeSimulationSignalPlots',true,... 'IncludeComparisonSignalPlots',true); % Export the Sim Output run dataset dataset = export(runDataset);
Тест завершается неуспешно, поскольку только одно из сравнений сигнала между выходным сигналом моделирования и критерием базовой линии находится в пределах допуска. Отчет о результатах представляет собой PDF-файл и открывается после его завершения. Дополнительные параметры создания отчетов см. в разделе sltest.testmanager.report страница ссылки на функцию.
В этом примере сравниваются данные сигнала между двумя моделями для проверки эквивалентности.
% Create the test file, test suite, and test case structure tf = sltest.testmanager.TestFile('API Test File'); ts = createTestSuite(tf,'API Test Suite'); tc = createTestCase(ts,'equivalence','Equivalence Test Case'); % Remove the default test suite tsDel = getTestSuiteByName(tf,'New Test Suite 1'); remove(tsDel); % Assign the system under test to the test case % for Simulation 1 and Simulation 2 setProperty(tc,'Model','sldemo_absbrake','SimulationIndex',1); setProperty(tc,'Model','sldemo_absbrake','SimulationIndex',2); % Add a parameter override to Simulation 1 and 2 ps1 = addParameterSet(tc,'Name','Parameter Set 1','SimulationIndex',1); po1 = addParameterOverride(ps1,'Rr',1.20); ps2 = addParameterSet(tc,'Name','Parameter Set 2','SimulationIndex',2); po2 = addParameterOverride(ps2,'Rr',1.24); % Capture equivalence criteria eq = captureEquivalenceCriteria(tc); % Set the equivalence criteria tolerance for one signal sc = getSignalCriteria(eq); sc(1).AbsTol = 2.2; % Run the test case and return an object with results data ResultsObj = run(tc); % Open the Test Manager so you can view the simulation % output and comparison data sltest.testmanager.view;
В разделе Результат критериев эквивалентности (Equivalence Criteria Result) результатов Диспетчера тестов (Test Manager) yout.Ww сигнал проходит из-за значения допуска. Другие сравнения сигналов не проходят, и общий тест завершается неуспешно.
В этом примере показано, как использовать тестовый пример моделирования для сбора результатов покрытия. Для получения покрытия необходима лицензия Simulink Coverage™.
% Create the test file, test suite, and test case structure tf = sltest.testmanager.TestFile('API Test File'); ts = createTestSuite(tf,'API Test Suite'); tc = createTestCase(ts,'simulation','Coverage Test Case'); % Remove the default test suite tsDel = getTestSuiteByName(tf,'New Test Suite 1'); remove(tsDel); % Assign the system under test to the test case setProperty(tc,'Model','sldemo_autotrans'); % Turn on coverage settings at test-file level cov = getCoverageSettings(tf); cov.RecordCoverage = true; % Enable MCDC and signal range coverage metrics cov.MetricSettings = 'mr'; % Run the test case and return an object with results data rs = run(tf); % Get the coverage results cr = getCoverageResults(rs); % Open the Test Manager to view results sltest.testmanager.view;
На панели «Результаты и артефакты» диспетчера тестов нажмите кнопку «Результаты». Можно просмотреть агрегированные результаты покрытия.
В этом примере показано, как создавать итерации теста. Итерации таблиц можно создавать программным способом, которые отображаются в разделе Итерации (Iterations) тестового случая. В этом примере создается тестовый пример моделирования и назначается сценарий редактора сигналов для каждой итерации.
% Create test file, test suite, and test case structure tf = sltest.testmanager.TestFile('Iterations Test File'); ts = getTestSuites(tf); tc = createTestCase(ts,'simulation','Simulation Iterations'); % Specify model as system under test setProperty(tc,'Model','sldemo_autotrans'); % Set up table iteration % Create iteration object testItr1 = sltestiteration; % Set iteration settings setTestParam(testItr1,'SignalEditorScenario','Passing Maneuver'); % Add the iteration to test case addIteration(tc,testItr1); % Set up another table iteration % Create iteration object testItr2 = sltestiteration; % Set iteration settings setTestParam(testItr2,'SignalEditorScenario','Coasting'); % Add the iteration to test case addIteration(tc,testItr2); % Run test case that contains iterations results = run(tc); % Get iteration results tcResults = getTestCaseResults(results); iterResults = getIterationResults(tcResults);