-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtestHydroSight.m
71 lines (58 loc) · 2.43 KB
/
testHydroSight.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function results = testHydroSight(runTests)
% Setup test environment and run suite.
%
% Setup includes closig the parpool and ensuring it does not autostart. The
% GUI layout toolbox is also installed. If the setup is successful, and
% only the setup is being done, then result equals 0, else -1;
%
% If runTests==true, then the test suite is also built and run. If so, then
% result equals a cell array of the TestResult objects.
%
% Initialise output
results = 0;
% Check matlab is after 2022a
if isMATLABReleaseOlderThan("R2022a")
error('HydroSight testing requires Matllab 2022a or later.');
end
% Import testing plugins
if nargin==0
runTests=true;
disp('Import testing plugins ...')
import matlab.unittest.TestRunner; %#ok<SIMPT>
import matlab.unittest.plugins.CodeCoveragePlugin; %#ok<SIMPT>
import matlab.unittest.plugins.XMLPlugin; %#ok<SIMPT>
import matlab.unittest.plugins.codecoverage.CoberturaFormat; %#ok<SIMPT>
end
% Add paths to unit tests
disp('Adding testing to path ...')
addpath('testing');
currentPath = pwd();
% Install GUI layout if not installed
try
if isempty(ver('layout'))
disp('Installing GUI Layout toolbox ...')
matlab.addons.toolbox.installToolbox(fullfile(currentPath,'testing','GUI Layout Toolbox 2.3.5.mltbx'),true);
end
catch ME
results = -1;
disp(['Installation of GUI Layout toolbox failed with error: ',ME.message]);
end
if runTests
disp('STARTING TESTING');
disp('--------------------------')
suite = testsuite(pwd, 'IncludeSubfolders', true);
runner = TestRunner.withTextOutput();
runner.addPlugin(XMLPlugin.producingJUnitFormat(fullfile('testing','results.xml')));
runner.addPlugin(CodeCoveragePlugin.forFolder({'.'}, 'IncludingSubfolders', true, 'Producing', CoberturaFormat(fullfile('testing','coverage.xml'))));
disp('TESTING: Running all tests ...');
results = runner.run(suite);
disp('TESTING: Finished running all tests.');
disp('TESTING: Displaying summary of all test results ...');
display(results);
disp('TESTING: Assessing if all tests were passed ...');
assertSuccess(results);
disp('FINISHED TESTING');
disp('--------------------------')
disp('')
end
end