Skip to content

Commit 19ea23d

Browse files
committed
unit test adjustments - add drawnow after verifyMethod and pauses in ProgressBar test to stop occasional failures
1 parent ce44b6b commit 19ea23d

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

test/+wt/+test/BaseWidgetTest.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ function verifyMethod(testCase, fcn, varargin)
165165
end
166166
fcn_send = @()fcn(testCase.Widget, varargin{:});
167167
testCase.verifyWarningFree(fcn_send);
168+
169+
% Give a moment for update to run
170+
drawnow
168171

169172
end %function
170173

test/+wt/+test/ProgressBar.m

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ function setup(testCase)
1515
% Set callback
1616
testCase.Widget.CancelPressedFcn = @(s,e)onCallbackTriggered(testCase,e);
1717

18-
% Ensure it renders
18+
% Ensure it renders and resizes fully
1919
drawnow
20+
pause(2) %needs time to resize, drawnow doesn't work!
2021

2122
end %function
2223

@@ -40,24 +41,25 @@ function testProgress(testCase)
4041

4142
% Start
4243
testCase.verifyMethod("startProgress")
44+
drawnow
4345

4446
% Start with message
4547
message = "Now started";
4648
testCase.verifyMethod("startProgress", message)
49+
drawnow
4750

4851
% Verify text and time
4952
testCase.verifyMatches(statusLabel.Text, message)
5053
testCase.verifyEqual(testCase.Widget.RemainingTime, seconds(inf))
5154

5255

5356
% Update 1
54-
pause(2)
5557
value = 0.3;
5658
message = "";
5759
testCase.verifyMethod(@setProgress, value)
60+
pause(2) %needs time to resize, drawnow doesn't work!
5861

5962
% Verify bar size
60-
pause(0.5) %needs to resize, drawnow doesn't work!
6163
testCase.assumeEqual(testCase.Widget.Units, 'pixels')
6264
wPos = testCase.Widget.Position;
6365
pos = testCase.Widget.ProgressPanel.Position;
@@ -72,13 +74,12 @@ function testProgress(testCase)
7274

7375

7476
% Update 2 with message
75-
pause(2)
7677
value = 0.6;
7778
message = "60% Complete";
7879
testCase.verifyMethod(@setProgress, value, message)
80+
pause(2) %needs time to resize, drawnow doesn't work!
7981

8082
% Verify bar size
81-
pause(0.5) %needs to resize, drawnow doesn't work!
8283
pos = testCase.Widget.ProgressPanel.Position;
8384
testCase.verifyGreaterThan(pos(3), wPos(3)/2)
8485
testCase.verifyLessThan(pos(3), wPos(3))
@@ -97,9 +98,9 @@ function testProgress(testCase)
9798
% Finish
9899
message = "";
99100
testCase.verifyMethod("finishProgress")
101+
pause(2) %needs time to resize, drawnow doesn't work!
100102

101103
% Verify bar size
102-
pause(0.5) %needs to resize, drawnow doesn't work!
103104
pos = testCase.Widget.ProgressPanel.Position;
104105
testCase.verifyEqual(pos(3), 0)
105106

@@ -174,7 +175,6 @@ function testShowCancel(testCase)
174175
testCase.verifyTrue(cancelButton.Visible);
175176

176177
% Advance progress
177-
pause(1.5)
178178
testCase.verifyMethod(@setProgress, 0.5);
179179

180180
% No cancel detected yet
@@ -198,12 +198,14 @@ function testShowTimeRemaining(testCase)
198198
% Start
199199
testCase.verifyMethod("startProgress")
200200

201-
% Update 1
201+
% Wait a few seconds so the progress bar tracks time
202202
pause(2)
203+
204+
% Update 1 - Tell the status bar it's 30% done after 2 seconds
203205
value = 0.3;
204206
testCase.verifyMethod(@setProgress, value)
205207

206-
% Verify the displayed time text
208+
% Verify the displayed time text is positive
207209
remTime = duration(timeLabel.Text,'InputFormat','mm:ss');
208210
testCase.verifyGreaterThanOrEqual(remTime, seconds(1))
209211

0 commit comments

Comments
 (0)