【问题标题】:parse error for Fixture in unit test framework单元测试框架中的 Fixture 解析错误
【发布时间】:2014-03-23 18:35:08
【问题描述】:

我正在尝试 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

即使运行它,也会发生错误。这里会发生什么?我已将文件夹设置为当前目录。

【问题讨论】:

    标签: matlab unit-testing xunit


    【解决方案1】:

    我相信自定义单元测试装置(特别是包 matlab.unittest.fixtures)的功能是在 MATLAB 的 R2013b 版本中引入的,如果您使用的是旧版本,它将不可用。

    您使用的是旧版本吗?

    【讨论】:

    • 同意这很可能是正在发生的事情,但简单的更正 - 夹具是在 R2014a 中引入的。
    • 那就是问题所在了。
    猜你喜欢
    • 2021-02-25
    • 2014-09-16
    • 1970-01-01
    • 2018-08-29
    • 1970-01-01
    • 1970-01-01
    • 2020-10-30
    • 2016-03-08
    • 2016-12-03
    相关资源
    最近更新 更多