Turn off UIFigure visibility during unit test

31 ビュー (過去 30 日間)
Rich006
Rich006 2025 年 10 月 8 日 13:25
回答済み: Adam Danz 2025 年 10 月 13 日 17:29
How can I run unit tests on an app without displaying the UIFigure during the tests? Rendering the graphics makes the tests take 10 times longer.
classdef UI < matlab.apps.AppBase
...
end
classdef tUI < matlab.uitest.TestCase
...
% many tests involving UI gestures
...
end

採用された回答

Adam Danz
Adam Danz 2025 年 10 月 13 日 17:29
Interaction tests using press, drag, etc, require figure visibility to be on in the App Testing Framework.
Make sure you're not unnecessarily creating/destroying the uifigure repeatedly between tests. In most cases, the figure/app only needs to be generated once during TestClassSetup and removed via a teardown. Reducinge the figure size may also help with performance.

その他の回答 (1 件)

Anjaneyulu Bairi
Anjaneyulu Bairi 2025 年 10 月 13 日 9:20
Hi,
In your code, you can create a function which turn on/off the visibilty of the figures. See the below code for example
function app = TurnOff(fig)
fig.Visible = 'off';
end
This way, you can show or hide any figure by changing its Visible property.
Hope this helps
  1 件のコメント
Rich006
Rich006 2025 年 10 月 13 日 11:49
編集済み: Rich006 2025 年 10 月 13 日 11:50
I think there is no way to do what I want to do, which is to turn off visibility during unit testing with gestures. If I make the UIFigure invisible as you suggest, I get the following error. It looks like the unit testing gestures require the UIFigure to be visible.
Error ID:
---------
'MATLAB:uiautomation:Driver:VisibleHierarchy'
--------------
Error Details:
--------------
Error using matlab.ui.internal.Driver/type
The component must have a visible hierarchy.
Error in matlab.uitest.internal.GestureProvider/type (line 181)
testCase.Driver.type(H, text, varargin{:});

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeApp Testing Framework についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by