我不确定在执行单元测试时如何传入变量.这些变量是从未放置在单元测试中的另一个函数创建的.
方法1:
classdef myTest < matlab.unittest.TestCase
properties
A, B, C
end
methods (Test)
function testDataCoverage(testCase)
expSol = afunction(A, B, C)
actSol = 10
testCase.verifyEqual(testCase, actSol, expSol)
end
end
end
我接下来尝试将变量创建函数(getData)放在单元测试中但遇到此错误:
Concrete class myTest does not define a TestParameter property named
BNew for the dataCoverage method. Either implement the property or
define the class as Abstract.
方法2:
classdef myTest < matlab.unittest.TestCase
properties
end
methods (Test)
function testDataCoverage(testCase)
[A, B, C] = getData()
expSol = afunction(A, B, C)
actSol = 10
testCase.verifyEqual(testCase, actSol, expSol)
end
function [A, B, C] = getData()
...code here...
end
function Sol = afunction(A, BNew, C)
...code here...
end
end
end