Borrar filtros
Borrar filtros

Matlab GUI unit tests, how to call private callback functions

6 visualizaciones (últimos 30 días)
Peter McCutcheon
Peter McCutcheon el 15 de Dic. de 2023
Respondida: Gowtham el 27 de Dic. de 2023
I have a complex GUI with a lot of parameters, each of which trigger a callback function. The callback function is private.
Then I am running Matlabs unit tests to change the value of a spinner, and ideally changing this value would trigger the callback and internally call this private function. However this does not happen by default when one remotely changes this spinner value, and as such it seems there is no way to trigger it's callback.
testCase.type(spinnerHandle,100) % this sets my spinner value
But then how to trigger the callback function?
Thanks
  1 comentario
Ayush Aniket
Ayush Aniket el 21 de Dic. de 2023
Hi Peter,
Can you share your code? I will try to replicate it on my end. It will help me answer the question. You can also share the relevant portion with respect to the "spinner" component.

Iniciar sesión para comentar.

Respuestas (1)

Gowtham
Gowtham el 27 de Dic. de 2023
Hello Peter,
I understand that you are trying to trigger a private callback function using unit tests.
This can be achieved by manually invoking the specific callback function after changing the value.
I suggest you follow the below steps to understand a sample demonstration:
  1. Start with creating an app in MATLAB App Designer.
  2. Add a Spinner component to test.
  3. Add a UI Button to use it as a trigger.
For a sample demonstration of the above process, kindly refer to the following code snippet:
% Value changed function: Spinner
function SpinnerValueChanged(app, event)
value = app.Spinner.Value;
% Print the value to verify the trigger
disp(value);
end
% Button pushed function: Button
function ButtonPushed(app, event)
% Test trigger
% Udpate the spinner value
spinnerHandle = app.Spinner;
spinnerHandle.Value = 100;
% Capture the callback function
callbackFcn = spinnerHandle.ValueChangedFcn;
% Check if the callback is specified and if it is a function handle
if ~isempty(callbackFcn)
if isa(callbackFcn, 'function_handle')
% Call the callback function directly
callbackFcn(spinnerHandle, event);
end
end
end
Below is the UI of the app and the expected output of the demonstration:
Kindly follow the below steps for testing:
  1. Increment the Spinner value
  2. Increment the Spinner value
  3. Increment the Spinner value
  4. Click the Button to trigger the callback internally
It appears you are looking to interact with a private method, and one approach might be to access it through an interface, specifically a public method of the same class that acts as a helper function.
Kindly refer to the following MathWorks Documentation(s) for further information on how to use the mentioned methods:
Hope this helps.
Best Regards,
Gowtham

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by