How to address default UI components of a function in automated unit test?

30 次查看(过去 30 天)
I have a legacy function which uses different default ui components like uigetfile, listdlg and inputdlg. It looks like the following function.
function y = doSomething(x1)
%% UIGETFILE
[nameFilex2,pathFilex2] = uigetfile('*.*');
x2 = readvars(fullfile(pathFilex2,nameFilex2));
%% LISTDLG
list = {'2','3','4'};
indx = listdlg('ListString',list);
x3 = str2double(list{indx});
%% INPUTDLG
x4 = inputdlg('Give a single digit number');
x4 = str2double(x4);
y = 10000*x1 + 1000*x2 + 100*x3 + 10*x4;
end
I want to create automated unit test cases without manual intervention. I could not find resources that specifies how to use unit testing framework for this type of cases. I found something similar here, but not quite the same.
Can you please help?
  1 个评论
Oliver Jaehrig
Oliver Jaehrig 2024-11-22,15:36
The link you shared also has a link to:
which is in my opinion the way to write tests for such interactive features.
In general you can create a mock for these features and the test uses this instead of opening the windows.
The simplest solution without using such a framework would be to simply overload the functions and provide outputs so your code does not hang in the lines which open the UI features.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by