MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

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


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


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
end


Create Example Test Class


In your working folder, create the file ExampleTest.m containing the following test
class.


classdef ExampleTest < matlab.unittest.TestCase
methods(Test)
function testOne(testCase) % Test fails
testCase.assertEqual(5, 4)
end
function testTwo(testCase) % Test passes
testCase.verifyEqual(5, 5)
end
function testThree(testCase) % Test passes
testCase.assertEqual(7*2, 14)
end
end
end


Add Plugin to TestRunner and Run Tests


At the command prompt, create a test suite from the ExampleTest class.


Create Custom Plugin
Free download pdf