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

30 visualizzazioni (ultimi 30 giorni)
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 Commento
Oliver Jaehrig
Oliver Jaehrig il 22 Nov 2024 alle 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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Data Distribution Plots in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by