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

조회 수: 4 (최근 30일)
SamForMat
SamForMat 2024년 11월 22일
댓글: Oliver Jaehrig 2024년 11월 22일
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일
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