Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

スクリプトによるテスト ケースの作成と実行

ベースライン テスト ケースの作成と実行

この例では、sltest.testmanager の関数、クラス、メソッドを使用して、テストを自動化してレポートを生成する方法を示します。テスト ケースの作成、テスト ケースの基準の編集、テスト ケースの実行、シミュレーション出力のエクスポート、結果レポートの生成をプログラムで実行できます。この例では、モデルのシミュレーション出力をベースラインと比較します。

% Open the model for this example
openExample('sldemo_absbrake');

% 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);

シミュレーション出力とベースライン基準の比較で許容誤差内の信号が 1 つしかないため、テスト ケースは失敗します。結果レポートは PDF であり、完了すると開きます。レポート生成の他の設定については、関数 sltest.testmanager.report のリファレンス ページを参照してください。

等価性テスト ケースの作成と実行

この例では、2 つのシミュレーション間で信号データを比較して等価性をテストします。

% Open the model for this example
openExample('sldemo_absbrake');

% 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;

テスト マネージャーの結果の [等価性基準の結果] セクションで、yout.Ww 信号は許容誤差値であるためパスします。他の信号の比較はパスせず、テスト ケース全体は失敗になります。

テスト ケースの実行とカバレッジの収集

この例では、シミュレーション テスト ケースを使用してカバレッジ結果を収集する方法を示します。カバレッジを収集するには Simulink® Coverage™ のライセンスが必要です。

% Open the model for this example
openExample('sldemo_autotrans');

% 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;

テスト マネージャーの [結果とアーティファクト] ペインで [結果] をクリックします。カバレッジの結果の集計を表示できます。

テスト ケースの反復の作成と実行

この例では、テスト反復を作成する方法を示します。テスト ケースの [反復] セクションに表示されるテーブルによる反復をプログラムで作成できます。この例では、シミュレーション テスト ケースを作成し、反復ごとに信号エディター シナリオを割り当てます。

% Open the model for this example
openExample('sldemo_autotrans');

% 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);

参考

| | | | | | | | | | |

関連するトピック