verifyError in a script based unit test
显示 更早的评论
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');
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Write Unit Tests 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!