end
function testWithdraw(testCase)
b = BankAccount(1234, 100);
b.withdraw(25);
testCase.verifyEqual(b.AccountBalance, 75);
end
function testNotifyInsufficientFunds(testCase)
callbackExecuted = false;
function testCallback(~,~)
callbackExecuted = true;
end
b = BankAccount(1234, 100);
b.addlistener('InsufficientFunds', @testCallback);
b.withdraw(50);
testCase.assertFalse(callbackExecuted, ...
'The callback should not have executed yet');
b.withdraw(60);
testCase.verifyTrue(callbackExecuted, ...
'The listener callback should have fired');
end
end
end
Create Test Suite
At the command prompt, create a test suite, ts, from the BankAccountTest test case.
ts = matlab.unittest.TestSuite.fromClass(?BankAccountTest);
Show Results with No Plugins
Create a test runner with no plugins.
runner = matlab.unittest.TestRunner.withNoPlugins;
res = runner.run(ts);
No output displayed.
Customize Test Runner
Add the custom plugin, TestRunProgressPlugin.
Add Plugin to Test Runner