Skip to content

Commit d558ed8

Browse files
committed
Update testing
1 parent be42291 commit d558ed8

25 files changed

+705
-155
lines changed

.github/workflows/ci.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: MATLAB Build
2+
3+
# Controls when the action will run.
4+
on:
5+
push:
6+
branches: [ release ]
7+
pull_request:
8+
branches: [ release ]
9+
workflow_dispatch:
10+
11+
jobs:
12+
test:
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
MATLABVersion: [R2021a,R2021b,R2022a,R2022b,R2023a,R2023b]
17+
runs-on: ubuntu-latest
18+
steps:
19+
# Checks-out your repository
20+
- uses: actions/checkout@v3
21+
22+
# Sets up MATLAB
23+
- name: Setup MATLAB
24+
uses: matlab-actions/setup-matlab@v1
25+
with:
26+
release: ${{ matrix.MATLABVersion }}
27+
28+
# Run all the tests
29+
- name: Run SmokeTests
30+
uses: matlab-actions/run-command@v1
31+
with:
32+
command: openProject(pwd); RunAllTests;
33+
34+
# Upload the test results as artifact
35+
- name: Upload TestResults
36+
uses: actions/upload-artifact@v3.1.3
37+
with:
38+
name: TestResults
39+
path: ./SoftwareTests/TestResults_${{ matrix.MATLABVersion }}.txt
40+
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+
58+
# Download the test results from artifact
59+
- name: Download TestResults
60+
uses: actions/download-artifact@v2.1.1
61+
with:
62+
name: TestResults
63+
path: ./SoftwareTests/
64+
65+
# Create the test results badge
66+
- name: Run CreateBadge
67+
uses: matlab-actions/run-command@v1
68+
with:
69+
command: openProject(pwd); CreateBadge;
70+
71+
# Commit the JSON for the MATLAB releases badge
72+
- name: Commit changed files
73+
continue-on-error: true
74+
run: |
75+
git config user.name "${{ github.workflow }} by ${{ github.actor }}"
76+
git config user.email "<>"
77+
git pull
78+
git add Images/TestedWith.json
79+
git commit Images/TestedWith.json -m "Update CI badges ${{ github.ref_name }}"
80+
git fetch
81+
git push

.gitignore

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
# MATLAB Drive
1111
*.MATLABDriveTag
1212

13-
# Compiled MEX files
13+
# Compiled files
1414
*.mex*
15+
*.p
16+
17+
# Compressed files
18+
*.zip
1519

1620
# Packaged app and toolbox files
1721
*.mlappinstall
@@ -23,9 +27,14 @@
2327
# Generated helpsearch folders
2428
helpsearch*/
2529

26-
# Simulink cache folder
30+
# Defined Simulink cache folder
2731
Utilities/SimulinkCache/*
2832

33+
# Standard code generation folders
34+
slprj/
35+
sccprj/
36+
codegen/
37+
2938
# Code generation file
3039
*.eep
3140
*.elf
@@ -35,5 +44,11 @@ Utilities/SimulinkCache/*
3544
# Cache files
3645
*.slxc
3746

38-
# Cloud based storage dotfile
39-
*.MATLABDriveTag
47+
# Project settings
48+
Utilities/ProjectSettings.mat
49+
50+
# Test results
51+
SoftwareTests/TestResults_*
52+
53+
# GitLab page fodler
54+
public/

.gitlab-ci.yml

Lines changed: 0 additions & 96 deletions
This file was deleted.

Images/MLMethodsClustering.png

174 KB
Loading

Scripts/ClusteringIntro.mlx

-654 Bytes
Binary file not shown.

Scripts/ClusteringMethods.mlx

5 Bytes
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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/FunctionTests.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
classdef FunctionTests < matlab.unittest.TestCase
2+
3+
methods(Test)
4+
5+
end % methods
6+
7+
end % classdef

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)