Given a medium-sized (scientific) codebase, how do you proceed to build a unittest-suite? I need to test local functions as well as hidden methods, but I would prefer not to mod
For private functions, you can work around the visibility rules creating a function handle:
%get handle for E:\WORKSPACE\MATLAB\private\object_of_test.m
testfun=getPrivateFunction('E:\WORKSPACE','MATLAB','private','object_of_test.m')
%call function
testfun(pi)
getPrivateFunction.m:
function handle=getPrivateFunction(varargin)
p=fullfile(varargin{:});
[d,f,~]=fileparts(p);
olddir=pwd;
cd(d);
handle=str2func(f);
cd(olddir);
end
For possible inputs of getPrivateFunction
please check the documentation for fullfile
, everything that results in a valid path is allowed.