verifyError in a script based unit test
Show older comments
Hi, my question is regarding the script-based unit testing framework. I would like to use the verifyError functionality and am struggling to generate a suitable testCase object that I can use in my script-based unit test.
For example, the run suite is called with:
import matlab.unittest.TestSuite;
import matlab.unittest.TestCase;
import matlab.unittest.TestRunner;
import matlab.unittest.plugins.TAPPlugin;
import matlab.unittest.plugins.ToFile;
suite = testsuite('unitTests','IncludingSubpackages',true);
runner = TestRunner.withTextOutput();
tapFile = fullfile(getenv('WORKSPACE'), sprintf('%s_results.tap', 'test'));
runner.addPlugin(TAPPlugin.producingOriginalFormat(ToFile(tapFile), 'LoggingLevel', 3, 'OutputDetail', 3));
results = runner.run(suite);
In the folder unitTests I would have the following script based unit test:
% Test to evaluate foo
% Initial Set-Up
a = 1;
%% Test 1. Verify Error Condition
% How can I get a test case here to call either:
% verifyError(testCase, @()foo('badArguement'), 'SomeError');
% or
% testCase.verifyError(@()foo('badArguement'), 'SomeError');
It seems that the following is not valid, as this instantiation is only for interactive use.
% Test to evaluate foo
% Initial Set-Up
a = 1;
testCase = matlab.unittest.TestCase.forInteractiveUse;
%% Test 1. Verify Error Condition
% How can I get a test case here to call either:
% verifyError(testCase, @()foo('badArguement'), 'SomeError');
% or
% testCase.verifyError(@()foo('badArguement'), 'SomeError');
or
% Test to evaluate foo
% Initial Set-Up
a = 1;
%% Test 1. Verify Error Condition
testCase = matlab.unittest.TestCase.forInteractiveUse;
% How can I get a test case here to call either:
% verifyError(testCase, @()foo('badArguement'), 'SomeError');
% or
% testCase.verifyError(@()foo('badArguement'), 'SomeError');
Accepted Answer
More Answers (0)
Categories
Find more on Write Unit Tests in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!