Skip to content

Commit

Permalink
Update SmokeTests.m
Browse files Browse the repository at this point in the history
  • Loading branch information
rweinsteMW committed Feb 6, 2024
1 parent f02c321 commit 5d40534
Showing 1 changed file with 55 additions and 59 deletions.
114 changes: 55 additions & 59 deletions SoftwareTests/SmokeTests.m
Original file line number Diff line number Diff line change
@@ -1,76 +1,72 @@
% Run these tests with runMyTests
% All tests so far are on code expected to run without errors
% If/when we end up with a version that _should_ error,
% please add it to this set of examples
classdef SmokeTests < matlab.unittest.TestCase

properties (ClassSetupParameter)
Project = {''};
properties
rootProject
results
end

properties (TestParameter)
Scripts;
end

methods (TestParameterDefinition,Static)

function Scripts = GetScriptName(Project)
RootFolder = currentProject().RootFolder;
Scripts = dir(fullfile(RootFolder,"Scripts","*.mlx"));
Scripts = {Scripts.name};
end
methods (TestClassSetup)

end

methods (TestClassSetup)

function SetUpSmokeTest(testCase,Project)
function setUpPath(testCase)

try
currentProject;
catch ME
warning("Project is not loaded.")
project = currentProject;
testCase.rootProject = project.RootFolder;
cd(testCase.rootProject)
catch
error("Load project prior to run tests")
end
end


end



methods(Test)

function SmokeRun(testCase,Scripts)
Filename = string(Scripts);
switch (Filename)
otherwise
SimpleSmokeTest(testCase,Filename)
end
end

end
testCase.log("Running in " + version)

end % function setUpPath

function setUpResults(testCase)
files = dir(fullfile(testCase.rootProject,"Scripts","*.mlx"));
testCase.results = struct;
testCase.results.Name = strings(size(files));
testCase.results.Passed = false(size(files));
testCase.results.Time = zeros(size(files));
testCase.results.Message = strings(size(files));
for k = 1:length(files)
testCase.results.Name(k) = string(files(k).name);
end

end % function setUpResults

methods (Access = private)
end % methods (TestClassSetup)

function SimpleSmokeTest(testCase,Filename)
methods(Test)

% Run the Smoke test
RootFolder = currentProject().RootFolder;
cd(RootFolder)
disp(">> Running " + Filename);
try
run(fullfile("Scripts",Filename));
catch ME
testCase.verifyTrue(false,ME.message);
end

% Log the opened figures to the test reports
Figures = findall(groot,'Type','figure');
Figures = flipud(Figures);
if ~isempty(Figures)
for f = 1:size(Figures,1)
FigDiag = matlab.unittest.diagnostics.FigureDiagnostic(Figures(f));
log(testCase,1,FigDiag);
function smokeTest(testCase)
myFiles = testCase.results.Name;
fid = fopen(fullfile("SoftwareTests","TestResults_"+release_version+".txt"),"w");
fprintf(fid,"Version,File,Status,ElapsedTime\n");
for kTest = 1:length(myFiles)
try
disp("Running " + myFiles(kTest))
tic
run(myFiles(kTest))
testCase.results.Time(kTest) = toc;
disp("Finished " + myFiles(kTest))
testCase.results.Passed(kTest) = true;
fprintf(fid,"%s,%s,%s,%s\n",release_version,myFiles(kTest),"passed",testCase.results.Time(kTest));
catch ME
testCase.results.Time(kTest) = toc;
disp("Failed " + myFiles(kTest) + " because " + ...
newline + ME.message)
testCase.results.Message(kTest) = ME.message;
fprintf(fid,"%s,%s,%s,%s\n",release_version,myFiles(kTest),"failed",testCase.results.Time(kTest));
end
clearvars -except kTest testCase myFiles fid
end
close all

fclose(fid);
struct2table(testCase.results)
end

end
Expand All @@ -84,4 +80,4 @@ function closeAllFigure(testCase)

end % methods (TestClassTeardown)

end
end

0 comments on commit 5d40534

Please sign in to comment.