MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
AssertionCountingPlugin Class Definition Summary

classdef AssertionCountingPlugin < ...
matlab.unittest.plugins.TestRunnerPlugin
properties
NumPassingAssertions = 0;
NumFailingAssertions = 0;
end
methods (Access = protected)
function runTestSuite(plugin, pluginData)
suiteSize = numel(pluginData.TestSuite);
fprintf('## Running a total of %d tests\n', suiteSize)
plugin.NumPassingAssertions = 0;
plugin.NumFailingAssertions = 0;
[email protected](...
plugin, pluginData);
fprintf('## Done running tests\n')
plugin.printAssertionSummary()
end
function fixture = createSharedTestFixture(plugin, pluginData)
fixture = createSharedTestFixture@...
matlab.unittest.plugins.TestRunnerPlugin(plugin, pluginData);
fixture.addlistener('AssertionPassed', ...
@(~,~)plugin.incrementPassingAssertionsCount);
fixture.addlistener('AssertionFailed', ...
@(~,~)plugin.incrementFailingAssertionsCount);
end
function testCase = createTestClassInstance(plugin, pluginData)
testCase = createTestClassInstance@...
matlab.unittest.plugins.TestRunnerPlugin(plugin, pluginData);
testCase.addlistener('AssertionPassed', ...
@(~,~)plugin.incrementPassingAssertionsCount);
testCase.addlistener('AssertionFailed', ...
@(~,~)plugin.incrementFailingAssertionsCount);
end
function testCase = createTestMethodInstance(plugin, pluginData)
testCase = createTestMethodInstance@...
matlab.unittest.plugins.TestRunnerPlugin(plugin, pluginData);
testCase.addlistener('AssertionPassed', ...
@(~,~)plugin.incrementPassingAssertionsCount);
testCase.addlistener('AssertionFailed', ...
@(~,~)plugin.incrementFailingAssertionsCount);
end

33 Unit Testing

Free download pdf