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" ));
0 commit comments