Unittest Matlab 2011版

Unittest Matlab 2011版,matlab,unit-testing,Matlab,Unit Testing,我想测试一个抛出错误的类,但我使用Matlab 2011b,我没有发现Matlab.unittest有Matlab.unittest.TestSuite.fromFile 我能用什么呢?一种方法是把它写成一个。这样,当您升级时,它将在较新版本的测试框架中开箱即用。同时,您可以通过调用脚本来运行测试 如果您现在无法升级,则可以编写类似以下帮助器函数的内容来测试脚本中的这些错误: function assertError(fcn, errorID) e = MException.empty; t

我想测试一个抛出错误的类,但我使用Matlab 2011b,我没有发现Matlab.unittest有Matlab.unittest.TestSuite.fromFile


我能用什么呢?

一种方法是把它写成一个。这样,当您升级时,它将在较新版本的测试框架中开箱即用。同时,您可以通过调用脚本来运行测试

如果您现在无法升级,则可以编写类似以下帮助器函数的内容来测试脚本中的这些错误:

function assertError(fcn, errorID)

e = MException.empty;
try
    fcn();
catch e
end
assert(~isempty(e), 'No error occurred. Expected an error with the id "%s"', errorID);
assert(strcmp(e.identifier, errorID), ...
    'Wrong error occurred. Expected id "%s", but id "%s" was thrown.', ...
    errorID, e.identifier);
要测试这一点:

>> assertError(@()error('some:id','Some message'), 'some:id') % no failure 
>> assertError(@()disp(5), 'some:id')
     5

Error using assertError (line 8)
No error occured. Expected an error with the id "some:id"

>> assertError(@()error('other:id','Some message'), 'some:id')
Error using assertError (line 9)
Wrong error occurred. Expected id "some:id", but id "other:id" was thrown.

>> 

将这项工作,我发现这个链接,我试图做的解释。但是,也许我错过了信息,如果我想测试下面的代码,我该怎么做:“function angles=rightTrisides Ifsides1我认为最好的方法是升级,如果可以的话,那么你拥有丰富的功能,拥有你需要的所有功能,并且非常健壮。然后您就有了verifyError和/或Throws约束。