Test value assignment fails
古いコメントを表示
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.
採用された回答
その他の回答 (1 件)
Gkn Cng
2022 年 2 月 20 日
0 投票
function testInput(value)
conf.filename = value
end
testCase.verifyError(@() testInput(-10), 'MATLAB:validators:mustBeNonnegative');
カテゴリ
ヘルプ センター および File Exchange で Noncentral t Distribution についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!