55 end
66
77 properties (TestParameter )
8- Scripts ;
8+ File ;
99 end
1010
1111 methods (TestParameterDefinition ,Static )
1212
13- function Scripts = GetScriptName(Project )
13+ function File = RetrieveFile(Project ) % #ok<INUSD>
14+ % Retrieve the files to test
1415 RootFolder = currentProject().RootFolder;
15- Scripts = dir(fullfile(RootFolder ," Scripts" ," *.mlx" ));
16- Scripts = {Scripts .name };
16+ File = dir(fullfile(RootFolder ," Scripts" ," *.mlx" ));
17+ File = {File .name };
1718 end
1819
1920 end
2021
2122 methods (TestClassSetup )
2223
23- function SetUpSmokeTest(testCase ,Project )
24+ function SetUpSmokeTest(testCase ,Project ) % #ok<INUSD>
2425 try
25- currentProject ;
26+ currentProject ;
27+ % Close the StartUp app if still open
28+ delete(findall(groot ,' Name' ,' StartUp App' ))
2629 catch ME
2730 warning(" Project is not loaded." )
2831 end
2932 end
3033
31-
3234 end
33-
34-
3535
3636 methods (Test )
3737
38- function SmokeRun(testCase ,Scripts )
39- Filename = string(Scripts );
40- switch (Filename )
41- case " FilteringIntro.mlx"
42- AudioSmokeTest(testCase ," FilteringIntroTest.mlx" )
43- case " AnalogToDigitalConversion.mlx"
44- AudioSmokeTest(testCase ," AnalogToDigitalConversionTest.mlx" )
45- case " FilterDesign.mlx"
46- FilterDesignSmokeTest(testCase ,Filename )
47- otherwise
48- SimpleSmokeTest(testCase ,Filename )
49- end
50- end
51-
52- end
53-
54-
55- methods (Access = private )
56-
57- function SimpleSmokeTest(testCase ,Filename )
38+ function SmokeRun(testCase ,File )
5839
59- % Run the Smoke test
40+ % Check file system
6041 RootFolder = currentProject().RootFolder;
6142 cd(RootFolder )
43+ Filename = string(File );
44+
45+ % Initialize test:
46+ % - Pre-populate workspace
47+ % - Overload functions
48+ InitFile = RetrieveInitFile(testCase ,Filename );
49+ run(InitFile );
50+
51+ % Run SmokeTest
6252 disp(" >> Running " + Filename );
6353 try
6454 run(fullfile(" Scripts" ,Filename ));
65- catch ME
66- testCase .verifyTrue(false ,ME .message );
55+ catch ME % #ok<*UNRCH>
56+ if ~any(strcmp(ME .identifier ,KnownIssuesID ))
57+ testCase .verifyTrue(false ,ME .message );
58+ end
6759 end
68-
69- % Log the opened figures to the test reports
60+
61+ % Log every figure created during run
7062 Figures = findall(groot ,' Type' ,' figure' );
7163 Figures = flipud(Figures );
7264 if ~isempty(Figures )
7365 for f = 1 : size(Figures ,1 )
74- FigDiag = matlab .unittest .diagnostics .FigureDiagnostic(Figures(f ));
75- % log(testCase,1,FigDiag);
66+ if ~isempty(Figures(f ).Number)
67+ FigDiag = matlab .unittest .diagnostics .FigureDiagnostic(Figures(f ),' Formats' ,' png' );
68+ log(testCase ,1 ,FigDiag );
69+ end
7670 end
7771 end
78- close all
79-
80- end
8172
82- function FilterDesignSmokeTest(testCase ,Filename )
83-
84- % Run the Smoke test
85- RootFolder = currentProject().RootFolder;
86- cd(RootFolder )
87- disp(" >> Running " + Filename );
88- try
89- run(fullfile(" Scripts" ,Filename ));
90- catch ME
91- switch ME .identifier
92- case ' MATLAB:minrhs'
93- otherwise
94- testCase .verifyTrue(false ,ME .message );
95- end
73+ % Close all figures and Simulink models
74+ close all force
75+ if any(matlab .addons .installedAddons().Name == " Simulink" )
76+ bdclose all
9677 end
97- end
98-
99- function AudioSmokeTest(testCase ,Filename )
10078
101- % Run the Smoke test
102- RootFolder = currentProject().RootFolder;
103- cd(RootFolder )
104- disp(" >> Running " + Filename );
105- try
106- run(fullfile(" Utilities" ,Filename ));
107- catch ME
108- switch ME .identifier
109- case ' MATLAB:minrhs'
110- otherwise
111- testCase .verifyTrue(false ,ME .message );
112- end
113- end
11479 end
115-
80+
11681 end
11782
118- methods (TestClassTeardown )
11983
120- function closeAllFigure(testCase )
121- close all force % Close figure windows
122- bdclose all % Close Simulink models
84+ methods (Access = private )
85+
86+ function y = RetrieveInitFile(testCase ,Filename )
87+ InitFile = " Init" +replace(Filename ," .mlx" ," .m" );
88+ InitFilePath = fullfile(currentProject().RootFolder," SoftwareTests" ," InitFiles" ,InitFile );
89+ if ~isfolder(fullfile(currentProject().RootFolder," SoftwareTests/InitFiles" ))
90+ mkdir(fullfile(currentProject().RootFolder," SoftwareTests/InitFiles" ))
91+ end
92+ if ~isfile(InitFilePath )
93+ writelines(" % Initialization script for " +Filename ,InitFilePath )
94+ writelines(" % ---- Known Issues -----" ,InitFilePath ,' WriteMode' ,' append' );
95+ writelines(" KnownIssuesID = " +char(34 )+char(34 )+" ;" ,InitFilePath ,' WriteMode' ,' append' );
96+ writelines(" % ---- Pre-run commands -----" ,InitFilePath ,' WriteMode' ,' append' );
97+ writelines(" " ,InitFilePath ,' WriteMode' ,' append' );
98+ end
99+ y = InitFilePath ;
123100 end
124101
125- end % methods (TestClassTeardown)
102+ end
126103
127- end
104+ end
0 commit comments