|
1 | 1 | classdef SolnSmokeTests < matlab.unittest.TestCase
|
2 | 2 |
|
3 |
| - properties |
4 |
| - RootFolder |
5 |
| - isSolnOnPath |
6 |
| - end |
7 |
| - |
8 |
| - properties (ClassSetupParameter) |
9 |
| - Project = {currentProject()}; |
10 |
| - end |
11 | 3 |
|
12 |
| - properties (TestParameter) |
13 |
| - File; |
14 |
| - end |
| 4 | + % properties |
| 5 | + % RootFolder |
| 6 | + % isSolnOnPath |
| 7 | + % end |
15 | 8 |
|
16 |
| - methods (TestParameterDefinition,Static) |
| 9 | + % properties (ClassSetupParameter) |
| 10 | + % Project = {currentProject()}; |
| 11 | + % end |
17 | 12 |
|
18 |
| - function File = GetScriptName(Project) |
19 |
| - % Retrieve student template files: |
20 |
| - RootFolder = Project.RootFolder; |
21 |
| - File = dir(fullfile(RootFolder,"Scripts","*.mlx")); |
22 |
| - File = {File.name}; |
23 |
| - end |
| 13 | + % properties (TestParameter) |
| 14 | + % File; |
| 15 | + % end |
24 | 16 |
|
25 |
| - end |
| 17 | + % methods (TestParameterDefinition,Static) |
26 | 18 |
|
27 |
| - methods (TestClassSetup) |
| 19 | + % function File = GetScriptName(Project) |
| 20 | + % % Retrieve student template files: |
| 21 | + % RootFolder = Project.RootFolder; |
| 22 | + % File = dir(fullfile(RootFolder,"Scripts","*.mlx")); |
| 23 | + % File = {File.name}; |
| 24 | + % end |
28 | 25 |
|
29 |
| - function SetUpPath(testCase,Project) |
30 |
| - % Navigate to project root folder: |
31 |
| - testCase.RootFolder = Project.RootFolder; |
32 |
| - cd(testCase.RootFolder) |
| 26 | + % end |
33 | 27 |
|
34 |
| - % Check that solutions are on path: |
35 |
| - testCase.isSolnOnPath = isfolder("Solutions"); |
36 |
| - if testCase.isSolnOnPath == 0 |
37 |
| - addpath(fullfile(testCase.RootFolder,"InstructorResources","Solutions")) |
38 |
| - end |
| 28 | + % methods (TestClassSetup) |
39 | 29 |
|
40 |
| - % Close the StartUp app if still open: |
41 |
| - delete(findall(groot,'Name','StartUp App')) |
| 30 | + % function SetUpPath(testCase,Project) |
| 31 | + % % Navigate to project root folder: |
| 32 | + % testCase.RootFolder = Project.RootFolder; |
| 33 | + % cd(testCase.RootFolder) |
42 | 34 |
|
43 |
| - % Log MATLAB version: |
44 |
| - testCase.log("Running in " + version) |
| 35 | + % % Check that solutions are on path: |
| 36 | + % testCase.isSolnOnPath = isfolder("Solutions"); |
| 37 | + % if testCase.isSolnOnPath == 0 |
| 38 | + % addpath(fullfile(testCase.RootFolder,"InstructorResources","Solutions")) |
| 39 | + % end |
45 | 40 |
|
46 |
| - end % function setUpPath |
| 41 | + % % Close the StartUp app if still open: |
| 42 | + % delete(findall(groot,'Name','StartUp App')) |
47 | 43 |
|
48 |
| - end % methods (TestClassSetup) |
| 44 | + % % Log MATLAB version: |
| 45 | + % testCase.log("Running in " + version) |
49 | 46 |
|
50 |
| - methods(Test) |
| 47 | + % end % function setUpPath |
51 | 48 |
|
52 |
| - % Check that solutions files exist for each of the student |
53 |
| - % templates |
54 |
| - function ExistSolns(testCase,File) |
55 |
| - SolutionName = replace(string(File),".mlx","Soln.mlx"); |
56 |
| - assert(exist(SolutionName,"file"),"Missing solutions for "+File); |
57 |
| - end |
| 49 | + % end % methods (TestClassSetup) |
58 | 50 |
|
| 51 | + % methods(Test) |
59 | 52 |
|
60 |
| - function SmokeRun(testCase,File) |
| 53 | + % % Check that solutions files exist for each of the student |
| 54 | + % % templates |
| 55 | + % function ExistSolns(testCase,File) |
| 56 | + % SolutionName = replace(string(File),".mlx","Soln.mlx"); |
| 57 | + % assert(exist(SolutionName,"file"),"Missing solutions for "+File); |
| 58 | + % end |
61 | 59 |
|
62 |
| - % Navigate to project root folder: |
63 |
| - cd(testCase.RootFolder) |
64 |
| - FileToRun = replace(string(File),".mlx","Soln.mlx"); |
65 | 60 |
|
66 |
| - % Pre-test: |
67 |
| - PreFiles = CheckPreFile(testCase,FileToRun); |
68 |
| - run(PreFiles); |
| 61 | + % function SmokeRun(testCase,File) |
69 | 62 |
|
70 |
| - % Run SmokeTest |
71 |
| - disp(">> Running " + FileToRun); |
72 |
| - try |
73 |
| - run(fullfile("InstructorResources","Solutions",FileToRun)); |
74 |
| - catch ME |
| 63 | + % % Navigate to project root folder: |
| 64 | + % cd(testCase.RootFolder) |
| 65 | + % FileToRun = replace(string(File),".mlx","Soln.mlx"); |
75 | 66 |
|
76 |
| - end |
| 67 | + % % Pre-test: |
| 68 | + % PreFiles = CheckPreFile(testCase,FileToRun); |
| 69 | + % run(PreFiles); |
77 | 70 |
|
78 |
| - % Post-test: |
79 |
| - PostFiles = CheckPostFile(testCase,FileToRun); |
80 |
| - run(PostFiles) |
| 71 | + % % Run SmokeTest |
| 72 | + % disp(">> Running " + FileToRun); |
| 73 | + % try |
| 74 | + % run(fullfile("InstructorResources","Solutions",FileToRun)); |
| 75 | + % catch ME |
81 | 76 |
|
82 |
| - % Log every figure created during run: |
83 |
| - Figures = findall(groot,'Type','figure'); |
84 |
| - Figures = flipud(Figures); |
85 |
| - if ~isempty(Figures) |
86 |
| - for f = 1:size(Figures,1) |
87 |
| - if ~isempty(Figures(f).Number) |
88 |
| - FigDiag = matlab.unittest.diagnostics.FigureDiagnostic(Figures(f),'Formats','png'); |
89 |
| - log(testCase,1,FigDiag); |
90 |
| - end |
91 |
| - end |
92 |
| - end |
| 77 | + % end |
93 | 78 |
|
94 |
| - % Close all figures and Simulink models |
95 |
| - close all force |
96 |
| - if any(matlab.addons.installedAddons().Name == "Simulink") |
97 |
| - bdclose all |
98 |
| - end |
| 79 | + % % Post-test: |
| 80 | + % PostFiles = CheckPostFile(testCase,FileToRun); |
| 81 | + % run(PostFiles) |
99 | 82 |
|
100 |
| - % Rethrow error if any |
101 |
| - if exist("ME","var") |
102 |
| - if ~any(strcmp(ME.identifier,KnownIssuesID)) |
103 |
| - rethrow(ME) |
104 |
| - end |
105 |
| - end |
| 83 | + % % Log every figure created during run: |
| 84 | + % Figures = findall(groot,'Type','figure'); |
| 85 | + % Figures = flipud(Figures); |
| 86 | + % if ~isempty(Figures) |
| 87 | + % for f = 1:size(Figures,1) |
| 88 | + % if ~isempty(Figures(f).Number) |
| 89 | + % FigDiag = matlab.unittest.diagnostics.FigureDiagnostic(Figures(f),'Formats','png'); |
| 90 | + % log(testCase,1,FigDiag); |
| 91 | + % end |
| 92 | + % end |
| 93 | + % end |
106 | 94 |
|
107 |
| - end |
| 95 | + % % Close all figures and Simulink models |
| 96 | + % close all force |
| 97 | + % if any(matlab.addons.installedAddons().Name == "Simulink") |
| 98 | + % bdclose all |
| 99 | + % end |
108 | 100 |
|
109 |
| - end |
| 101 | + % % Rethrow error if any |
| 102 | + % if exist("ME","var") |
| 103 | + % if ~any(strcmp(ME.identifier,KnownIssuesID)) |
| 104 | + % rethrow(ME) |
| 105 | + % end |
| 106 | + % end |
| 107 | + |
| 108 | + % end |
| 109 | + |
| 110 | + % end |
110 | 111 |
|
111 |
| - methods (Access = private) |
112 |
| - |
113 |
| - function Path = CheckPreFile(testCase,Filename) |
114 |
| - PreFile = "Pre"+replace(Filename,".mlx",".m"); |
115 |
| - PreFilePath = fullfile(testCase.RootFolder,"SoftwareTests","PreFiles",PreFile); |
116 |
| - if ~isfolder(fullfile(testCase.RootFolder,"SoftwareTests/PreFiles")) |
117 |
| - mkdir(fullfile(testCase.RootFolder,"SoftwareTests/PreFiles")) |
118 |
| - end |
119 |
| - if ~isfile(PreFilePath) |
120 |
| - writelines("% Pre-run script for "+Filename,PreFilePath) |
121 |
| - writelines("% ---- Known Issues -----",PreFilePath,'WriteMode','append'); |
122 |
| - writelines("KnownIssuesID = "+char(34)+char(34)+";",PreFilePath,'WriteMode','append'); |
123 |
| - writelines("% ---- Pre-run commands -----",PreFilePath,'WriteMode','append'); |
124 |
| - writelines(" ",PreFilePath,'WriteMode','append'); |
125 |
| - end |
126 |
| - Path = PreFilePath; |
127 |
| - end |
128 |
| - |
129 |
| - function Path = CheckPostFile(testCase,Filename) |
130 |
| - PostFile = "Post"+replace(Filename,".mlx",".m"); |
131 |
| - PostFilePath = fullfile(testCase.RootFolder,"SoftwareTests","PostFiles",PostFile); |
132 |
| - if ~isfolder(fullfile(testCase.RootFolder,"SoftwareTests/PostFiles")) |
133 |
| - mkdir(fullfile(testCase.RootFolder,"SoftwareTests/PostFiles")) |
134 |
| - end |
135 |
| - if ~isfile(PostFilePath) |
136 |
| - writelines("% Post-run script for "+Filename,PostFilePath) |
137 |
| - writelines("% ---- Post-run commands -----",PostFilePath,'WriteMode','append'); |
138 |
| - writelines(" ",PostFilePath,'WriteMode','append'); |
139 |
| - end |
140 |
| - Path = PostFilePath; |
141 |
| - end |
142 |
| - |
143 |
| - end |
| 112 | + % methods (Access = private) |
| 113 | + |
| 114 | + % function Path = CheckPreFile(testCase,Filename) |
| 115 | + % PreFile = "Pre"+replace(Filename,".mlx",".m"); |
| 116 | + % PreFilePath = fullfile(testCase.RootFolder,"SoftwareTests","PreFiles",PreFile); |
| 117 | + % if ~isfolder(fullfile(testCase.RootFolder,"SoftwareTests/PreFiles")) |
| 118 | + % mkdir(fullfile(testCase.RootFolder,"SoftwareTests/PreFiles")) |
| 119 | + % end |
| 120 | + % if ~isfile(PreFilePath) |
| 121 | + % writelines("% Pre-run script for "+Filename,PreFilePath) |
| 122 | + % writelines("% ---- Known Issues -----",PreFilePath,'WriteMode','append'); |
| 123 | + % writelines("KnownIssuesID = "+char(34)+char(34)+";",PreFilePath,'WriteMode','append'); |
| 124 | + % writelines("% ---- Pre-run commands -----",PreFilePath,'WriteMode','append'); |
| 125 | + % writelines(" ",PreFilePath,'WriteMode','append'); |
| 126 | + % end |
| 127 | + % Path = PreFilePath; |
| 128 | + % end |
| 129 | + |
| 130 | + % function Path = CheckPostFile(testCase,Filename) |
| 131 | + % PostFile = "Post"+replace(Filename,".mlx",".m"); |
| 132 | + % PostFilePath = fullfile(testCase.RootFolder,"SoftwareTests","PostFiles",PostFile); |
| 133 | + % if ~isfolder(fullfile(testCase.RootFolder,"SoftwareTests/PostFiles")) |
| 134 | + % mkdir(fullfile(testCase.RootFolder,"SoftwareTests/PostFiles")) |
| 135 | + % end |
| 136 | + % if ~isfile(PostFilePath) |
| 137 | + % writelines("% Post-run script for "+Filename,PostFilePath) |
| 138 | + % writelines("% ---- Post-run commands -----",PostFilePath,'WriteMode','append'); |
| 139 | + % writelines(" ",PostFilePath,'WriteMode','append'); |
| 140 | + % end |
| 141 | + % Path = PostFilePath; |
| 142 | + % end |
| 143 | + |
| 144 | + % end |
| 145 | + |
144 | 146 |
|
145 | 147 | end
|
0 commit comments