Test value assignment fails
Show older comments
Hello,
I have a class that has some properties defined with
(SetAccess=private)
I want to create a unit test that verifies that assigning a value to these properties will throw an error.
something like:
function testCannotChangeProperties(tc)
conf = ConfigurationFile();
conf.filename = 'woo'; % I want to verify that this throws the error 'MATLAB:class:SetProhibited'. You cannot set the read-only property 'filename' of ConfigurationFile
end
Do i really need to wrap that call inside a function to be able to test it?
function testCannotChangeProperties(tc)
conf = ConfigurationFile();
tc.verifyError(@()conf.setFileName('woo'), 'MATLAB:class:SetProhibited')
end
This is not a solution I can use, because the:
conf.filename = 'woo';
Situation is still not tested.
Accepted Answer
More Answers (1)
Gkn Cng
on 20 Feb 2022
0 votes
function testInput(value)
conf.filename = value
end
testCase.verifyError(@() testInput(-10), 'MATLAB:validators:mustBeNonnegative');
Categories
Find more on Linear Algebra 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!