Skip to content

Commit 70098b5

Browse files
committed
Improve test analysis to handle function tests
1 parent 8bf2a73 commit 70098b5

2 files changed

Lines changed: 31 additions & 11 deletions

File tree

SoftwareTests/CrossReleaseTestResults.m

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,18 @@ function verifyAllTestsPassedInArtifact(testCase, ResultArtifactPath)
6868
rootFolder = testCase.Project{1}.RootFolder;
6969
resultFiles = FileCollection.fromPaths(fullfile(rootFolder, "public", ResultArtifactPath, "*.mat")).paths;
7070

71-
loadedData = load(resultFiles, "result");
72-
testCase.assertTrue(isfield(loadedData, "result"), ...
73-
"Missing variable 'result' in artifact: " + ResultArtifactPath);
71+
allResults = [];
72+
for i = 1:numel(resultFiles)
73+
loadedData = load(resultFiles(i), "result");
74+
testCase.assertTrue(isfield(loadedData, "result"), ...
75+
"Missing variable 'result' in artifact: " + resultFiles(i));
76+
allResults = [allResults, loadedData.result]; %#ok<AGROW>
77+
end
7478

75-
result = loadedData.result;
76-
testCase.assertNotEmpty(result, ...
79+
testCase.assertNotEmpty(allResults, ...
7780
"Result array is empty in artifact: " + ResultArtifactPath);
7881

79-
passedValues = [result.Passed];
82+
passedValues = [allResults.Passed];
8083
testCase.assertNotEmpty(passedValues, ...
8184
"Result.Passed is empty in artifact: " + ResultArtifactPath);
8285

SoftwareTests/FunctionTests.m

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
% Run these tests with
2-
% runMyTests
3-
% OR
4-
% results = runtests(tLibrary)
5-
% table(results)
61
classdef FunctionTests < matlab.unittest.TestCase
72

83
methods(Test)
@@ -17,4 +12,26 @@ function RunShowTaylor(testCase)
1712

1813
end % methods
1914

15+
methods(TestMethodTeardown)
16+
17+
function cleanUpFigures(testCase)
18+
figures = findall(groot, 'Type', 'figure');
19+
figures = flipud(figures);
20+
if ~isempty(figures)
21+
for iFigure = 1:size(figures, 1)
22+
if ~isempty(figures(iFigure).Number)
23+
figDiag = matlab.unittest.diagnostics.FigureDiagnostic(figures(iFigure), 'Formats', 'png');
24+
log(testCase, 1, figDiag);
25+
end
26+
end
27+
end
28+
29+
% Cleanup avoids cross-test contamination in desktop and CI runs.
30+
close all force
31+
if any(matlab.addons.installedAddons().Name == "Simulink")
32+
bdclose all
33+
end
34+
end
35+
end % TestMethodTeardown
36+
2037
end % classdef

0 commit comments

Comments
 (0)