How to convert an array of sltest.tes​tmanager.T​estCase to sltest.tes​tmanger.Te​stSuite?

2 views (last 30 days)
ts = array of sltest.testmanager.TestCase
run(ts)
Error:
Index exceeds the number of array elements (9).
Error in stm.internal.apiDetail.runWrapper
Error in sltest.testmanager.Test.run (line 30)
resultObj = stm.internal.apiDetail.runWrapper('idMap',idMap, ...
Error in sltest.testmanager.TestCase/run (line 6)
resultObj = sltest.testmanager.Test.run(obj, 0, varargin{:});
To make this run as TestSuite, I need to convert ts(sltest.testmanager.TestCase) to ts1(sltest.testmanager.TestSuite).

Answers (1)

Aishwarya Shukla
Aishwarya Shukla on 29 Mar 2023
To convert an array of sltest.testmanager.TestCase objects to a sltest.testmanager.TestSuite, you can use the sltest.testmanager.TestSuite.fromArray method. Here's an example:
% Create an array of sltest.testmanager.TestCase objects
tc1 = sltest.testmanager.TestCase('myTest1');
tc2 = sltest.testmanager.TestCase('myTest2');
ts = [tc1, tc2];
% Convert the array to a sltest.testmanager.TestSuite
ts1 = sltest.testmanager.TestSuite.fromArray(ts);
% Run the TestSuite
resultObj = run(ts1);
In this example, we create an array of two sltest.testmanager.TestCase objects (tc1 and tc2) and then convert it to a sltest.testmanager.TestSuite using the sltest.testmanager.TestSuite.fromArray method. We then run the resulting ts1 object using the run function.
  2 Comments
Montina
Montina on 4 Apr 2023
Thanks @Aishwarya Shukla. I tried with this. But it is not working. Everytime it throws the error: The class sltest.testmanager.TestSuite has no Constant property or Static method named 'fromArray'. Checked for documentation too.
Aishwarya Shukla
Aishwarya Shukla on 4 Apr 2023
Hi @Montina, To convert an array of sltest.testmanager.TestCase objects to a sltest.testmanager.TestSuite, you can also use the "add" method of the TestSuite object. Here's an example:
% Create an array of sltest.testmanager.TestCase objects
tc1 = sltest.testmanager.TestCase('myTest1');
tc2 = sltest.testmanager.TestCase('myTest2');
ts = sltest.testmanager.TestSuite('myTestSuite');
% Add test cases to the TestSuite
ts.add(tc1);
ts.add(tc2);
% Run the TestSuite
resultObj = run(ts);
In this example, we create an array of two sltest.testmanager.TestCase objects (tc1 and tc2) and then create a sltest.testmanager.TestSuite object (ts) with a name 'myTestSuite'. We then add the test cases to the TestSuite object using the "add" method. Finally, we run the resulting ts object using the run function.
I hope this helps! Let me know if you have any further questions.

Sign in to comment.

Categories

Find more on Testing Frameworks in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!