Parsing Test Manager Information with Nested Folders

1 visualización (últimos 30 días)
Will Schulke
Will Schulke el 8 de Jul. de 2022
Respondida: Swetha Murali el 11 de Jul. de 2022
I have a test Manager set up with cases as follows in teh folder structure for example.
Tests
General
ConfigA
Test Case1
Test Case2
Config B
Test Case1
Test Case2
Extreme
ConfigA
Test Case1
Test Case2
Config B
Test Case1
Test Case2
My scripts in the past were successful in looping through all the cases to get and update values. I am not nested in the folders one level deeper and I cannot find a way for this to work.
Previously it looked like this
Tests
Config A
Test Case1
Test Case2
ConfigB
Test Case 1
Test Case 2
I have reorganize to be only one level folder deep for now as before, but there are reasons why I would want to organize it differently that maybe this simple example does not show it the best.
Here is what my script looks like. It no longer finds all the test cases such to loop through them because they are nested a folder deeper now. I am thinking it is a limit of the function API to the Test Manager. This is a little advanced for my current skill level so maybe I am missing something.
% Read source file
tf = sltest.testmanager.TestFile(testFile);
ts = getTestSuites(tf);
TestCaseArray = GetTestCaseArray(ts);
[~, TestCaseSize] = size(TestCaseArray);
for i=1:TestCaseSize
%Do something for each test case.
end
Thanks ... thought I may ask before I post it as a improvment if that is what it turns out to be.

Respuesta aceptada

Swetha Murali
Swetha Murali el 11 de Jul. de 2022
I think the logic maybe in the way "GetTestCaseArray" function works. Here is one I wrote that will work for either one of these test structures
function allTestCases = getAllTestCaseObjectsInTestFile(testFileName)
tf = sltest.testmanager.TestFile(testFileName);
ts = getTestSuites(tf);
allTestCases = getTestCaseFromTestSuite(ts);
end
function tc = getTestCaseFromTestSuite(ts)
% Recursively get all test cases from testsuites in a nested folder
% structure
tc = [];
for i=1:numel(ts)
tc = [tc,getTestCases(ts(i))];
subts = getTestSuites(ts(i));
tc = [tc,getTestCaseFromTestSuite(subts)];
end
end
You can try replacing your code with a call to the above function, something like this:
TestCaseArray = getAllTestCaseObjectsInTestFile(testFile);
[~, TestCaseSize] = size(TestCaseArray);
for i=1:TestCaseSize
%Do something for each test case.
end

Más respuestas (1)

Mark McBroom
Mark McBroom el 11 de Jul. de 2022
Try using this syntax to get all test cases in a nested folder structure:
suite = TestSuite.fromFolder(pwd, 'IncludingSubfolders', true);
result = run(suite);

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by