MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

testCase.addlistener('AssertionPassed', ...
@(~,~)plugin.incrementPassingAssertionsCount);
testCase.addlistener('AssertionFailed', ...
@(~,~)plugin.incrementFailingAssertionsCount);
end
end


Extend Running of Single Test Suite Element


Extend runTest to display the name of each test at run time. Include this function in a
methods block with protected access. Like all plugin methods, when you override this
method you must invoke the corresponding superclass method.


methods (Access = protected)
function runTest(plugin, pluginData)
fprintf('### Running test: %s\n', pluginData.Name)


[email protected](...
plugin, pluginData);
end
end


Define Helper Functions


In a methods block with private access, define three helper functions. These functions
increment the number of passing or failing assertions, and print out the assertion count
summary.


methods (Access = private)
function incrementPassingAssertionsCount(plugin)
plugin.NumPassingAssertions = plugin.NumPassingAssertions + 1;
end


function incrementFailingAssertionsCount(plugin)
plugin.NumFailingAssertions = plugin.NumFailingAssertions + 1;
end


function printAssertionSummary(plugin)
fprintf('%s\n', repmat('_', 1, 30))
fprintf('Total Assertions: %d\n', ...
plugin.NumPassingAssertions + plugin.NumFailingAssertions)
fprintf('\t%d Passed, %d Failed\n', ...
plugin.NumPassingAssertions, plugin.NumFailingAssertions)
end
end


Create Custom Plugin
Free download pdf