www.gusucode.com > simulinktest 案例源码程序 matlab代码 > simulinktest/ReuseTestAssessmentBlocksUsingALibraryExample.m

    %% Reuse Test Assessments Using a Library
%
% This example shows how to reuse test assessments contained in a test 
% sequence block using a linked block from a library.

% Copyright 2015 The MathWorks, Inc.


%% 
%
% When you create a test harness, you can include a standalone Test
% Sequence block for test assessments (a Test Assessment block). 
% Often, assessments cover multiple test cases, 
% making it convenient to reuse the same Test Assessment
% block. Test assessment reuse has these advantages:
%
% * Assessments are stored in a single source. If the requirements change,
% you update only the assessments in the library.
% * You can link to test requirements from the source. Linking from the
% source reduces the number of requirements links to manage.
%
% To reuse a standalone Test Assessment block in multiple test harnesses,
% create the Test Assessment block in a library, and reuse the Test Assessment
% block in multiple test harnesses by way of linked
% blocks. 
%
% Consider using a library for high-level test assessments that correspond
% to multiple test cases.
%
% You can also create reusable assessments in a library using blocks from
% the Model Verification library in Simulink.

%% Explore the Test Sequence Example Model
% 
% 1. Open the model. At the command line, enter:
%
%   sltestTestSequenceExample

sltestTestSequenceExample

%%
%
% 2. Click the badge on the |shift_controller| subsystem and open the
% |controller_harness| test harness.

sltest.harness.open('sltestTestSequenceExample/shift_controller','controller_harness')

%%
%
% The Test Assessment block contains four assertions that define the 
% assessment criteria:
%
%   assert(speed >= 0)
%   assert(throttle >= 0)
%   assert(throttle <= 100)
%   assert(gear > 0)

%% Create a Library for the Test Assessments
%
% # In the test harness, select *File > New > Library*.
% # Save the new library as |AssessmentLibrary| in a writable location on the
% MATLAB(R) path.
% # Copy the Test Assessment block from the test harness to the library, and then
% delete the Test Assessment block from the test harness.
% # Save the library.

%%
% <<../assessment_reuse_newlibrary.png>>

%% Create a Linked Test Assessment Block in Test Harnesses
%
% Copy the Test Assessment block from the library to the
% test harness to create a linked block.
%
% # In the test harness, enable the library link display. 
% Select *Display > Library Links > All*.
% # Copy the Test Assessment block from |AssessmentLibrary| into
% |controller_harness|. The block displays a library link badge.
% # Connect the signal inputs to the Test Assessment block.

%%
% <<../assessment_reuse_paste_firstharness.png>>

%% Edit the Assessment Block in the Library
%
% # Unlock the library. Select *Diagram > Unlock Library*.
% # Add a fifth assertion to the Test Sequence block:  |assert(gear < 5);|
% # Save and close the library. Closing locks the library.

%%

close_system('sltestTestSequenceExample',0);