Can I run unit tests in the MCR?
5 views (last 30 days)
Show older comments
I'd like to write class-based component unit tests and then run a suite of them as a callback to a button in an MCR-deployed GUI application. But the MCR has no command line to output to. Would it even run?
0 Comments
Answers (2)
Andy Campbell
on 31 May 2018
Hi Bob,
The test framework doesn't require the use or even presence of the command window. By default using runtests much of the output will indeed go there, but you can run the tests silently using a non default runner. For example, if you create a runner with no plugins installed it will be a completely silent run. It won't show you any diagnostics, it will simply run the tests and produce a result array that tells you which passed and which failed:
>> runner = matlab.unittest.TestRunner.withNoPlugins;
>> result = runner.run(testsuite(...));
The result will still give you valid information about whether the tests passed or failed. If you'd like to get more information such as failure diagnostics you could also write your own plugin. You should be able to get to some relevant documentation on how to do this by going here.
Here you could even write a plugin which takes the results and presents it directly in your app as you please.
Hope that helps. Andy
0 Comments
OCDER
on 30 May 2018
Instead of using the Application Compiler, use mcc. It'll give you a command window that opens up with the GUI. But the downside is it'll open up your GUI with the command window all the time...
%assuming you have myGUI.m and myGUI.fig
mcc -m myGUI.m
%use disp or fprintf(1, 'your text\n') to output the message to the command window
Another way to do this is to use msgbox to output your unit test results, but then you'll get a lot of popups...
msgbox('unit test completed!')
Another way to do this is to make a textbox component in your GUI that updates with new text (the fake console). The unit test function should have the text handle as an input.
% --- From myGUI.m file ---
function pushbutton1_Callback(hObject, eventdata, handles)
%Assuming you have a text box in your GUI with the tag "text1", then pass on that handle:
runUnitTest(handles.text1)
function runUnitTest(texthandle)
set(texthandle, 'string', 'unit test completed!')
Here's a similar thread: https://www.mathworks.com/matlabcentral/answers/33629-problem-with-displaying-output-of-executable
0 Comments
See Also
Categories
Find more on Run Unit Tests in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!