【发布时间】:2016-01-03 16:24:01
【问题描述】:
我有一个m-file,其中有几个测试定义为本地函数。它们是从主函数调用的:
function tests = main_function_test()
tests = functiontests(localfunctions);
end
我正在做一些容忍的断言,所以我需要在每个本地函数中导入:
import matlab.unittest.constraints.IsEqualTo;
import matlab.unittest.constraints.AbsoluteTolerance;
为了做出如下形式的断言:
verifyThat(testCase, actual, IsEqualTo(expected, ...
'Within', AbsoluteTolerance(0.00001)));
是否可以只导入一次这些函数,以便在每个本地函数中重复使用它们?
【问题讨论】:
-
没有。每the documentation:
Scope is the function and the function does not share the import list of the parent function. If the import list is needed in a MATLAB function or script and in any local functions, you must call the import function for each function. -
谢谢,@excaza,我没有找到那个摘录。您可以将此添加为答案。除非存在一些技巧,否则我想这应该是公认的答案。
标签: matlab unit-testing