How to isolate unittests in matlab

Given the average (scientific) codebase, how are you going to build the unittest package? I need to check local functions as well as hidden methods, but I would prefer not to modify / extend classes so far. Is this possible or do I need to somehow introduce test samples? How am I best to implement this?

Thanks.

PS: I know that unittesting usually refers to testing whole units, but my objects are quite complex and have very bizarre methods that are constantly changing by the team.

+2
source share
1 answer

For private functions, you can bypass the visibility rules that create the function descriptor:

%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

getPrivateFunction, , fullfile, , , .

+1

Source: https://habr.com/ru/post/1627308/


All Articles