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 Center および File ExchangeData Distribution Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by