mardi 16 avril 2019

How to access the test index in the unit test framework of MATLAB/Simulink?

I started doing unit tests for a Simulink model. I used the following blog as a starting point. My test function is currently similar to this:

function tests = exampleTest
tests = functiontests(localfunctions);
end

function setupOnce(testCase)
testCase.TestData.mdlName = 'myModel';
load_system(testCase.TestData.mdlName);
end

function teardownOnce(testCase)
close_system(testCase.TestData.mdlName, 0)
end

function test1(testCase)
set_param([testCase.TestData.mdlName, '/mySubsystem'], 'myMaskParameter','1')
set_param(...);
set_param(...);
sim(testCase.TestData.mdlName);
testCase.verifyEqual(mySubsystemOutput,1)
end

function test2(testCase)
...
end

Now, I want to change this script so that it would be easy and fast to modify if I ever want to create a lot of tests (e.g. ­­> 100). I'm trying to find a way to initialize a variable that would contain all the parameters (i.e. the ones I declare in the set_param) for each unit test (and maybe even the expected values). I'm thinking the set_param could be placed in a function setup(testCase) instead of in the individual test, which would remove a lot of lines in the code. However, to achieve this I need to know the actual index of the testCase. I didn't find anything in the documentation or in examples about a way to access this information. Is there a way? Also, is my approach a good approach for doing what I want to do (i.e. regroup variables that change in a common function in order to limit the number of lines that need to be modified)?

Aucun commentaire:

Enregistrer un commentaire