Parsing Test Manager Information with Nested Folders

조회 수: 3 (최근 30일)
Will Schulke
Will Schulke 2022년 7월 8일
답변: Swetha Murali 2022년 7월 11일
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.

채택된 답변

Swetha Murali
Swetha Murali 2022년 7월 11일
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

추가 답변 (1개)

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

카테고리

Help CenterFile Exchange에서 Outputs에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by