Skip to content

Commit 9f532ec

Browse files
committed
Updated Unit Test
1 parent b6e462e commit 9f532ec

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

Tests/AdmittanceScanHVDCUnitTest.m

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
classdef AdmittanceScanHVDCUnitTest < matlab.unittest.TestCase
2+
% This MATLAB unit test is used to run all the codes used in the
3+
% Design and Analysis of Admittance Scan PRBS example.
4+
% Copyright 2024 The MathWorks, Inc.
5+
properties
6+
modelname = "HVDCScan";
7+
openfigureListBefore
8+
end
9+
methods(TestMethodSetup)
10+
function listOpenFigures(testCase)
11+
% List all open figures
12+
testCase.openfigureListBefore = findall(0,'Type','Figure');
13+
end
14+
end
15+
methods(TestMethodTeardown)
16+
function closeOpenedFigures(testCase)
17+
% Close all figure opened during test
18+
figureListAfter = findall(0,'Type','Figure');
19+
figuresOpenedByTest = setdiff(figureListAfter, testCase.openfigureListBefore);
20+
arrayfun(@close, figuresOpenedByTest);
21+
end
22+
end
23+
methods (Test)
24+
function AdmittanceScanHVDCSimulateModel(testCase)
25+
% Test for the Admittance HVDC example model
26+
% Load system and add teardown
27+
load_system(testCase.modelname)
28+
testCase.addTeardown(@()close_system(testCase.modelname, 0));
29+
% Set parameters
30+
set_param(testCase.modelname, StopTime = "0.5")
31+
% Simulate model
32+
sim(testCase.modelname);
33+
end
34+
function HVDCScanRunMLX(testCase)
35+
% Test runs the main |.mlx| for VSC HVDC Scan
36+
% Load system and add teardown
37+
load_system(testCase.modelname)
38+
testCase.addTeardown(@()close_system(testCase.modelname, 0));
39+
40+
%suppress warning
41+
warningID = 'Ident:estimation:tfestLowerOrder';
42+
warningState = warning('query', warningID);
43+
warning('off', warningID);
44+
testCase.addTeardown(@() warning(warningState.state,warningID));
45+
46+
% Set parameters
47+
set_param(testCase.modelname, StopTime = "6")
48+
% Run |.mlx| script
49+
HVDCParameters
50+
VSCHVDCScanandStabilityAnalysis
51+
end
52+
end % methods (Test)
53+
end % classdef
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
%% Script to run unit tests
2+
% This script runs tests for component-level and system-level tests.
3+
% Note that tests for detailed model applications are not run
4+
% to avoid long-running tests.
5+
% Copyright 2024 The MathWorks, Inc.
6+
relStr = matlabRelease().Release;
7+
disp("This is MATLAB " + relStr + ".")
8+
topFolder = currentProject().RootFolder;
9+
%% Create test suite
10+
suite = matlab.unittest.TestSuite.fromFile(...
11+
fullfile(topFolder, "Tests", "AdmittanceScanHVDCUnitTest.m"));
12+
%% Create test runner
13+
runner = matlab.unittest.TestRunner.withTextOutput( ...
14+
OutputDetail = matlab.unittest.Verbosity.Detailed);
15+
%% MATLAB Code Coverage Report
16+
coverageReportFolder = fullfile(topFolder, "coverage" + relStr);
17+
if not(isfolder(coverageReportFolder))
18+
mkdir(coverageReportFolder)
19+
end
20+
coverageReport = matlab.unittest.plugins.codecoverage.CoverageReport( ...
21+
coverageReportFolder, ...
22+
MainFile = "Admittance Scan Test Coverage" + relStr + ".html" );
23+
plugin = matlab.unittest.plugins.CodeCoveragePlugin.forFile(...
24+
[...
25+
fullfile(topFolder, "ScriptsData", "HVDC", "ScanOfVSCHVDC", "generalizedNyquistPlotwithCrossing.m")...
26+
fullfile(topFolder, "ScriptsData", "HVDC", "ScanOfVSCHVDC", "VSCHVDCScanandStabilityAnalysis.mlx")], ...
27+
Producing = coverageReport );
28+
addPlugin(runner, plugin)
29+
%% Run tests
30+
results = run(runner, suite);
31+
out = assertSuccess(results);
32+
disp(out);

0 commit comments

Comments
 (0)