Is there a way to change order of TestCases in sltest.tes​tmanager.T​estSuite programmatically?

I'm importing content of a TestFile from external server. Everything works well, but there is a case, when order of the TestCases changes, and I want to refrect it in the parent sltest.testmanager.TestSuite.
I thought that sltest.testmanager.moveTests might be helpful, as it accepts array of objects to be moved, and moving those testcases to a temporary TestSuite, then back to the original place. Unfortunately order of the array doesn't seem to be respected - testcases are landing in their original order.
% sort test cases within this test suite
unsortedTCs = parentTS.getTestCases();
if ~isempty(unsortedTCs)
% collect the indexes of the referred testcases
sorting_array = getOriginalIndexes(unsortedTCs);
[~, ind] = sort(sorting_array);
sortedTCs = unsortedTCs(ind);
tempTestSuite = createTestSuite(parentTS, 'temp');
sltest.testmanager.moveTests(sortedTCs, tempTestSuite);
sltest.testmanager.moveTests(sortedTCs, parentTS);
remove(tempTestSuite);
end
Any hint?
In UI I can drag&drop testcases to change their order - looking for similar functionality over API.
Thank you!

回答 (1 件)

Paul Urban
Paul Urban 2022 年 11 月 10 日
You can use the moveTest api’s starting with R2020b release to move tests with the following. We will request the documentation to be update with this example
sltest.testmanager.moveTests(tc1, tc2); % move tc1 below tc2
sltest.testmanager.moveTests(tc3, tc1); % move tc3 to top before tc1

2 件のコメント

Chris Armstrong
Chris Armstrong 2026 年 5 月 4 日 13:54
I am using R2024A and finding that if I have test manager open when I run the commands, then the test suites are ordered as I want them, but upon reload then the order has changed. Is there anything in the background that could cause Test Suites to be re-ordered to a different criteria?
Steven Lord
Steven Lord 2026 年 5 月 4 日 17:42
Why does the order of your tests matter? That sounds like you may have Interacting Tests, a sub-category of the Erratic Tests test smell.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeFunction-Based Unit Tests についてさらに検索

製品

質問済み:

2022 年 11 月 3 日

コメント済み:

2026 年 5 月 4 日 17:42

Community Treasure Hunt

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

Start Hunting!

Translated by