How to Create and Link a Roll-Up Analysis Test Case
How can you ensure system requirements are being met when designing a system architecture? Create a test case, of course!
Learn how to create and link a roll-up analysis test case using System Composer™, Requirements Toolbox™, and the MATLAB® Unit Test framework.
Published: 9 Oct 2024
Hi, I’m Pat. I’m a Product Manager at MathWorks.
In this video, I will show you how to create and link a roll-up analysis test case using System Composer, Requirements Toolbox, and the MATLAB Unit Test framework.
Click on the link below to find the example I started with to try this workflow for yourself.
Let’s say I’m a Systems Engineer creating the physical architecture for a robot system. I’m in the early stages of modeling the architecture, but I want to ensure the architecture I’m designing meets some high-level system requirements.
Here is my architecture model so far, which I’ve developed using System Composer. It’s a pretty simple architecture, including components for the Computer, Robot, and Power Source. Not a bad start!
There is a high-level system requirement stating that “the system weight shall be less than 100 kg”.
I can view this requirement in the Requirements Editor.
I can see that the requirement has been implemented by the Robot System Physical Architecture model in System Composer and can navigate to the model using this hyperlink.
There is not a test case linked to this requirement yet. Let’s create one.
The goal with the test case is to ensure that the total system weight does not exceed 100 kg.
I can verify this requirement by performing a roll-up analysis to calculate the total weight. Fortunately, I already have a CostAndWeightRollupAnalysis function to accomplish that. I won’t go into detail on this function now, but you can learn more using the example linked to below.
Let’s see how we can use the roll-up analysis function in a test case.
First, we need to create a new test case using the MATLAB Unit Test framework. I prefer using class-based tests – because I’m a classy engineer. To create a new class-based test case, click New -> Test Class.
A new Test Class includes a couple boilerplate methods, such as TestClassSetup and TestMethodSetup. Just to keep things simple for now, I will leave those blank.
Let’s save the file as “weightTest.m” and focus our efforts on the Test methods section. This is where we can create specific test methods which we can link to requirements.
The default test method with a new Test Class is an unimplementedTest function which should fail because we haven’t written any test logic yet. We can confirm this by simply running the test.
Great!
Let’s replace this function with a new one called “verifyWeight” which will have two parts:
1. Run a roll-up analysis to calculate the system weight using the CostAndWeightRollupAnalysis function, the result of which is stored as “rollupWeight”.
2. Verify the result of the analysis meets the requirement. This uses the verifyLessThan qualification method, which – as its name suggests – verifies that the rollupWeight is less than 100 kg.
For more information on these methods and more about the MATLAB Unit Test framework, take a look at our documentation.
Now that we have a verification function in a test case, we can link the function to the requirement.
We can do this by selecting the verifyWeight method, then going to the requirement in the Requirements Editor, clicking “Add Link” -> “Link from selection in MATLAB Editor”.
While in the Requirements Editor, I can confirm that the requirement has a linked test case and we can navigate to the verification method using the hyperlink.
I can run all tests associated with a requirement by right-clicking on the requirement in the Requirements Editor and selecting “Run Tests” or by running the runTests function to run all tests linked to requirements in a requirements set.
Success!
I want to make sure this test case “lives” with the requirement and architecture model as the system evolves. To do this, I have organized everything into a MATLAB Project, which can be checked in to a version control system. This test can be used repeatedly – either by me or by any of my colleagues- as the architecture evolves to ensure the requirement is being met.
Where else is this approach useful?
You can use this approach to run any arbitrary MATLAB code and verify the result within a MATLAB Unit Test test case. The test case can then be linked to a requirement. Another common use case is to retrieve test data from external systems, often stored in Microsoft Excel spreadsheets.
To learn more, check out our documentation.