我正在尝试在MathWorks网站上找到的以下教程 http://www.mathworks.co.uk/help/matlab/matlab_prog/create-basic-custom-fixture.html
但是,当我尝试运行代码时,会出现以下错误:
Error using FormatHexFixture
The specified superclass 'matlab.unittest.fixtures.Fixture'
contains a parse error or cannot be found on MATLAB's
search path, possibly shadowed by another file with the
same name.
代码如下:
classdef FormatHexFixture < matlab.unittest.fixtures.Fixture
properties (Access = private)
OriginalFormat;
end
methods
function setup(fixture)
fixture.OriginalFormat = get(0, 'Format');
set(0, 'Format', 'hex')
end
function teardown(fixture)
set(0, 'format', fixture.OriginalFormat);
end
end
end
使用SampleTest代码:
classdef SampleTest < matlab.unittest.TestCase
methods(Test)
function test1(testCase)
testCase.applyFixture(FormatHexFixture)
actStr = getColumnForDisplay([1;2;3], 'Small Integers');
expStr = ['Small Integers '
'3ff0000000000000'
'4000000000000000'
'4008000000000000'];
testCase.verifyEqual(actStr, expStr);
end
end
end
function str = getColumnForDisplay(values, title)
elements = cell(numel(values)+1, 1);
elements{1} = title;
for idx = 1:numel(values)
elements{idx+1} = displayNumber(values(idx));
end
str = char(elements);
end
function str = displayNumber(n)
str = strtrim(evalc('disp(n);'));
end
即使运行此操作,也会发生错误。这可能会发生什么?我已将文件夹设置为当前目录。
答案 0 :(得分:1)
我相信自定义单元测试装置(特别是包matlab.unittest.fixtures
)的功能是在MATLAB的R2013b版本中引入的,如果您使用的是旧版本,它将无法使用。< / p>
你是旧版本吗?