Skip to content

Commit 5deea8d

Browse files
committed
Update testing
1 parent bd6f40c commit 5deea8d

File tree

14 files changed

+234
-150
lines changed

14 files changed

+234
-150
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,23 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
MATLABVersion: [R2023a,R2023b]
16+
MATLABVersion: [R2021a,R2021b,R2022a,R2022b,R2023a,R2023b]
1717
runs-on: ubuntu-latest
1818
steps:
19-
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
19+
# Checks-out your repository
2020
- uses: actions/checkout@v3
2121

22-
# Sets up MATLAB on the GitHub Actions runner
22+
# Sets up MATLAB
2323
- name: Setup MATLAB
2424
uses: matlab-actions/setup-matlab@v1
2525
with:
2626
release: ${{ matrix.MATLABVersion }}
2727

28-
# Run SmokeTests
28+
# Run all the tests
2929
- name: Run SmokeTests
3030
uses: matlab-actions/run-command@v1
3131
with:
32-
command: openProject(pwd); results = runtests(fullfile("SoftwareTests","SmokeTests.m")); assertSuccess(results);
33-
34-
# Run FunctionTests
35-
- name: Run FunctionTests
36-
uses: matlab-actions/run-command@v1
37-
with:
38-
command: openProject(pwd); results = runtests(fullfile("SoftwareTests","FunctionTests.m")); assertSuccess(results);
32+
command: openProject(pwd); RunAllTests;
3933

4034
# Upload the test results as artifact
4135
- name: Upload TestResults
@@ -44,6 +38,23 @@ jobs:
4438
name: TestResults
4539
path: ./SoftwareTests/TestResults_${{ matrix.MATLABVersion }}.txt
4640

41+
badge:
42+
if: ${{ always() }}
43+
needs: [test]
44+
strategy:
45+
fail-fast: false
46+
runs-on: ubuntu-latest
47+
steps:
48+
49+
# Checks-out your repository
50+
- uses: actions/checkout@v3
51+
52+
# Sets up R2023b
53+
- name: Setup MATLAB
54+
uses: matlab-actions/setup-matlab@v1
55+
with:
56+
release: R2023b
57+
4758
# Download the test results from artifact
4859
- name: Download TestResults
4960
uses: actions/download-artifact@v2.1.1
@@ -55,14 +66,16 @@ jobs:
5566
- name: Run CreateBadge
5667
uses: matlab-actions/run-command@v1
5768
with:
58-
command: openProject(pwd); results = runtests(fullfile("SoftwareTests","CreateBadge.m"));
69+
command: openProject(pwd); CreateBadge;
5970

6071
# Commit the JSON for the MATLAB releases badge
6172
- name: Commit changed files
6273
continue-on-error: true
6374
run: |
6475
git config user.name "${{ github.workflow }} by ${{ github.actor }}"
6576
git config user.email "<>"
77+
git pull
78+
git add Images/TestedWith.json
6679
git commit Images/TestedWith.json -m "Update CI badges ${{ github.ref_name }}"
6780
git fetch
6881
git push

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,6 @@ Utilities/ProjectSettings.mat
4949

5050
# Test results
5151
SoftwareTests/TestResults_*
52+
53+
# GitLab page fodler
54+
public/

Scripts/FE1_ProgrammaticML.mlx

5 Bytes
Binary file not shown.

Scripts/FE2_LoadForecastDL.mlx

-11 Bytes
Binary file not shown.

Scripts/LoadForecastRegression.mlx

-4 Bytes
Binary file not shown.

Scripts/MachineLearningIntro.mlx

-38.8 KB
Binary file not shown.

SoftwareTests/CheckTestResults.m

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
classdef CheckTestResults < matlab.unittest.TestCase
2+
3+
properties (SetAccess = protected)
4+
end
5+
6+
properties (ClassSetupParameter)
7+
Project = {''};
8+
end
9+
10+
properties (TestParameter)
11+
Version
12+
end
13+
14+
15+
methods (TestParameterDefinition,Static)
16+
17+
function Version = GetResults(Project)
18+
RootFolder = currentProject().RootFolder;
19+
Version = dir(fullfile(RootFolder,"SoftwareTests","TestResults*.txt"));
20+
Version = extractBetween([Version.name],"TestResults_",".txt");
21+
end
22+
23+
end
24+
25+
methods (TestClassSetup)
26+
27+
function SetUpSmokeTest(testCase,Project)
28+
try
29+
currentProject;
30+
catch
31+
error("Project is not loaded.")
32+
end
33+
end
34+
35+
end
36+
37+
methods(Test)
38+
39+
function CheckResults(testCase,Version)
40+
File = fullfile("SoftwareTests","TestResults_"+Version+".txt");
41+
Results = readtable(File,TextType="string");
42+
testCase.verifyTrue(all(Results.Passed));
43+
end
44+
45+
end
46+
47+
end

SoftwareTests/CreateBadge.m

Lines changed: 28 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,28 @@
1-
% Run these tests with runMyTests
2-
% All tests so far are on code expected to run without errors
3-
% If/when we end up with a version that _should_ error,
4-
% please add it to this set of examples
5-
classdef CreateBadge < matlab.unittest.TestCase
6-
7-
properties
8-
rootProject
9-
results
10-
end
11-
12-
13-
methods (TestClassSetup)
14-
15-
function setUpPath(testCase)
16-
17-
try
18-
project = currentProject;
19-
testCase.rootProject = project.RootFolder;
20-
cd(testCase.rootProject)
21-
catch
22-
error("Load project prior to run tests")
23-
end
24-
25-
testCase.log("Running in " + version)
26-
27-
end % function setUpPath
28-
29-
function readResults(testCase)
30-
Release = string([]);
31-
Passed = [];
32-
testCase.results = table(Release,Passed);
33-
34-
ResultFiles = dir("SoftwareTests"+filesep+"TestResults_*");
35-
for kFiles = 1:size(ResultFiles)
36-
Results = readtable(fullfile(ResultFiles(kFiles).folder,ResultFiles(kFiles).name),...
37-
Delimiter=",",TextType="string");
38-
Release = Results.Version(1);
39-
Passed = all(Results.Status == "passed");
40-
testCase.results(end+1,:) = table(Release,Passed);
41-
end
42-
end
43-
44-
end % methods (TestClassSetup)
45-
46-
methods(Test)
47-
48-
function writeBadge(testCase)
49-
50-
% Create JSON
51-
badgeInfo = struct;
52-
badgeInfo.schemaVersion = 1;
53-
badgeInfo.label = "tested with";
54-
badgeInfo.message = "";
55-
56-
% Check that results exist:
57-
if size(testCase.results,1) == 0
58-
badgeInfo.message = "None";
59-
badgeInfo.color = "failed";
60-
else
61-
for i = 1:size(testCase.results,1)
62-
if testCase.results.Passed(i)
63-
if badgeInfo.message ~= ""
64-
badgeInfo.message = badgeInfo.message + " | ";
65-
end
66-
badgeInfo.message = badgeInfo.message + string(testCase.results.Release(i));
67-
end
68-
end
69-
badgeInfo.color = "success";
70-
end
71-
72-
% Write JSON file out
73-
badgeJSON = jsonencode(badgeInfo);
74-
fid = fopen(fullfile("Images","TestedWith.json"),"w");
75-
fwrite(fid,badgeJSON);
76-
fclose(fid);
77-
78-
end
79-
80-
end
81-
82-
end
1+
% Create the test suite with SmokeTest and Function test if they exist
2+
Suite = testsuite("CheckTestResults");
3+
4+
% Create a runner with no plugins
5+
Runner = matlab.unittest.TestRunner.withNoPlugins;
6+
7+
% Run the test suite
8+
Results = Runner.run(Suite);
9+
10+
% Format the results in a table and save them
11+
Results = table(Results');
12+
Results = Results(Results.Passed,:);
13+
Version = extractBetween(string(Results.Name),"Version=",")");
14+
15+
16+
% Format the JSON file
17+
Badge = struct;
18+
Badge.schemaVersion = 1;
19+
Badge.label = "Tested with";
20+
if size(Results,1) >= 1
21+
Badge.color = "success"
22+
Badge.message = join(Version," | ");
23+
else
24+
Badge.color = "failure";
25+
Badge.message = "Pipeline fails";
26+
end
27+
Badge = jsonencode(Badge);
28+
writelines(Badge,fullfile("Images","TestedWith.json"));

SoftwareTests/RunAllTests.m

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
function RunAllTest(EnableReport,ReportFolder)
2+
arguments
3+
EnableReport (1,1) logical = false;
4+
ReportFolder (1,1) string = "public";
5+
end
6+
7+
import matlab.unittest.plugins.TestReportPlugin;
8+
9+
% Create a runner
10+
Runner = matlab.unittest.TestRunner.withTextOutput;
11+
if EnableReport
12+
Folder = fullfile(currentProject().RootFolder,ReportFolder);
13+
if ~isfolder(Folder)
14+
mkdir(Folder)
15+
else
16+
rmdir(Folder,'s')
17+
mkdir(Folder)
18+
end
19+
Plugin = TestReportPlugin.producingHTML(Folder,...
20+
"IncludingPassingDiagnostics",true,...
21+
"IncludingCommandWindowText",true,...
22+
"LoggingLevel",matlab.automation.Verbosity(1));
23+
Runner.addPlugin(Plugin);
24+
end
25+
26+
% Create the test suite with SmokeTest and Function test if they exist
27+
Suite = testsuite("SmokeTests");
28+
Suite = [Suite testsuite("FunctionTests")];
29+
30+
% Run the test suite
31+
Results = Runner.run(Suite);
32+
33+
if EnableReport
34+
web(fullfile(Folder,"index.html"))
35+
else
36+
T = table(Results);
37+
disp(newline + "Test summary:")
38+
disp(T)
39+
end
40+
41+
% Format the results in a table and save them
42+
ResultsTable = table(Results')
43+
writetable(ResultsTable,fullfile("SoftwareTests","TestResults_"+release_version+".txt"));
44+
45+
% Assert success of test
46+
assertSuccess(Results);
47+
48+
end

0 commit comments

Comments
 (0)