Parsing Test Manager Information with Nested Folders

1 回表示 (過去 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 Center および File ExchangeOutputs についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by