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

30 views (last 30 days)
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 Comment
Oliver Jaehrig
Oliver Jaehrig on 22 Nov 2024 at 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.

Sign in to comment.

Answers (0)

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!