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!