How to programmatically link requirements to test case and check whether a model has requirements associated?

조회 수: 12 (최근 30일)

I want to use command line API with Requirement toolbox in MATLAB 2021b. I wants to know:How to programmatically link requirements to test case?How to programmatically check whether a model has requirements associated? 

채택된 답변

MathWorks Support Team
MathWorks Support Team 2025년 8월 28일 0:00
How to programmatically link requirements to test case?
The function "find" from Requirement Toolbox can find requirements. reference and link set. Please refer to the link for more information: 
1. Open the project. At the MATLAB® command prompt, enter:
>> slreqCCProjectStart
This will pop up a project that contains sample model, requirement documents and test file. 
2. Open the controller model, test file and requirements. At the command prompt, enter:
>> open_system("models/crs_controller") >> sltest.testmanager.load('DriverSwRequest_Tests.mldatx') >> slreq.open('crs_req_func_spec')
3. Modify the requirement and test files only for the purpose of this example. Because most requirements in the project has already been linked with their corresponding test case, for this example, we will delete the existing link for one requirement and test case pair, and try to recreate the link programmatically. 
  • Find the requirement Index 1.6 Enable Switch Detection, and click it. 
  • On the right panel, under the "Links - Verified by" section, delete the existing "Enable button" link.
  • Now, the requirement 1.6 will have no test case associated, and we are ready to recreate the link using command line. 
4. Define the test case that you would like to link requirements to. At the command line, enter: 
>> tf = sltest.testmanager.load('DriverSwRequest_Tests.mldatx'); >> ts = getTestSuites(tf); >> tc = getTestCaseByName(ts, 'Enable button');
This is to load test file, get test suite and test case. 
5. Define the requirement. At the command line, enter: 
>> reqSet = slreq.load('crs_req_func_spec'); >> requirement = reqSet.find('Type', 'Requirement', 'SID', 9);
6. Create link. At the command line, enter: 
>> link = slreq.createLink(tc, requirement);
After executing this command, you should be able to see that in "Requirement Editor", under the "Links-Verified by" section of the requirement 1.6 (i.e. Enable Switch Detection), there is a link "Enable button". 
7. Run test cases, update verification and fetch verification results. At command line, enter: 
>> ro = sltest.testmanager.run; >> reqSet.updateVerificationStatus >> status = reqSet.getVerificationStatus;
And if "Verification Status" is turned on in Requirement Editor, you will also be able to visualize verification results as bar. 
How to programmatically check whether a model has requirements associated? 
% open up an example project slreqCCProjectStart % open up model modelName = 'crs_controller'; open_system(modelName); % define the variable  isLinkToRequirement = false; % find whether any links are associated with the model links = slreq.find('Type', 'Link'); % Because links can be associated to test case, other model files etc, we need to go through each link's destination label and check  for i=1:numel(links)    if strcmp(links(i).destination.domain, 'linktype_rmi_slreq')      isLinkToRequirement = true;       break    end end

추가 답변 (0개)

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by