Merge lp:~aacid/unity8/betterUnityTestCaseErrors into lp:unity8

Proposed by Albert Astals Cid on 2016-03-31
Status: Merged
Approved by: Michael Terry on 2016-04-13
Approved revision: 2322
Merged at revision: 2356
Proposed branch: lp:~aacid/unity8/betterUnityTestCaseErrors
Merge into: lp:unity8
Diff against target: 320 lines (+97/-19)
3 files modified
tests/qmltests/Dash/Previews/tst_PreviewImageGallery.qml (+3/-2)
tests/qmltests/Dash/tst_Card.qml (+10/-10)
tests/utils/modules/Unity/Test/UnityTestCase.qml (+84/-7)
To merge this branch: bzr merge lp:~aacid/unity8/betterUnityTestCaseErrors
Reviewer Review Type Date Requested Status
Michael Terry 2016-03-31 Approve on 2016-04-13
Unity8 CI Bot continuous-integration Needs Fixing on 2016-04-13
Review via email: mp+290628@code.launchpad.net

Commit Message

Better error message if the item does not exist

Instead of
  Cannot read property 'width' of null
and a line pointing to UnityTestCase.qml, you get
   No item given
and a line pointing to the offending code

Description of the Change

 * Are there any related MPs required for this MP to build/function as expected?
No

 * Did you perform an exploratory manual test run of your code change and any related functionality?
N/A

 * Did you make sure that your branch does not contain spurious tags?
Yes

 * If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?
N/A

 * If you changed the UI, has there been a design review?
N/A

To post a comment you must log in.
Unity8 CI Bot (unity8-ci-bot) wrote :

FAILED: Continuous integration, rev:2321
https://unity8-jenkins.ubuntu.com/job/lp-unity8-ci/907/
Executed test runs:
    UNSTABLE: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=vivid+overlay,testname=qmluitests.sh/489
    UNSTABLE: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=xenial,testname=qmluitests.sh/489
    FAILURE: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=phone-armhf,release=vivid+overlay,testname=autopilot.sh/489/console
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/1218
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/1194
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/1194
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=vivid+overlay/1192
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=vivid+overlay/1192/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial/1192
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial/1192/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=vivid+overlay/1192
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=vivid+overlay/1192/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial/1192
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial/1192/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=vivid+overlay/1192
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=vivid+overlay/1192/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial/1192
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial/1192/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-unity8-ci/907/rebuild

review: Needs Fixing (continuous-integration)
Michael Terry (mterry) wrote :

Looks like a good change, but testCard and testPreviewImageGallery fail, because of properties defined with findObject.

review: Needs Fixing
2322. By Albert Astals Cid on 2016-04-13

Merge & make tests pass

Albert Astals Cid (aacid) wrote :

> Looks like a good change, but testCard and testPreviewImageGallery fail,
> because of properties defined with findObject.

I clearly remember fixing those tests, but obviously it didn't either happen or i forgot to push them :D

Pushed now :)

Unity8 CI Bot (unity8-ci-bot) wrote :

FAILED: Continuous integration, rev:2322
https://unity8-jenkins.ubuntu.com/job/lp-unity8-ci/985/
Executed test runs:
    UNSTABLE: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=vivid+overlay,testname=qmluitests.sh/558
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=xenial,testname=qmluitests.sh/558
    UNSTABLE: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=phone-armhf,release=vivid+overlay,testname=autopilot.sh/558
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/1327
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/1298
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/1298
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=vivid+overlay/1296
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=vivid+overlay/1296/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial/1296
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial/1296/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=vivid+overlay/1296
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=vivid+overlay/1296/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial/1296
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial/1296/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=vivid+overlay/1296
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=vivid+overlay/1296/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial/1296
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial/1296/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-unity8-ci/985/rebuild

review: Needs Fixing (continuous-integration)
Michael Terry (mterry) wrote :

 * Did you perform an exploratory manual test run of the code change and any related functionality?
 Yes

 * Did CI run pass? If not, please explain why.
 No, for unrelated reasons

 * Did you make sure that the branch does not contain spurious tags?
 Yes

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/qmltests/Dash/Previews/tst_PreviewImageGallery.qml'
2--- tests/qmltests/Dash/Previews/tst_PreviewImageGallery.qml 2016-01-08 14:19:08 +0000
3+++ tests/qmltests/Dash/Previews/tst_PreviewImageGallery.qml 2016-04-13 08:16:30 +0000
4@@ -70,8 +70,6 @@
5 when: windowShown
6
7 property Item overlay: findChild(imageGallery.rootItem, "overlay")
8- property Item overlayCloseButton: findChild(overlay, "overlayCloseButton")
9- property Item overlayListView: findChild(overlay, "overlayListView")
10
11 function cleanup() {
12 overlay.hide();
13@@ -87,6 +85,7 @@
14 }
15
16 function test_overlayOpenClose() {
17+ var overlayCloseButton = findChild(overlay, "overlayCloseButton");
18 var image0 = findChild(imageGallery, "previewImage0");
19 mouseClick(image0);
20 tryCompare(overlay, "visible", true);
21@@ -97,6 +96,7 @@
22 }
23
24 function test_overlayShowHideHeader() {
25+ var overlayCloseButton = findChild(overlay, "overlayCloseButton");
26 var image0 = findChild(imageGallery, "previewImage0");
27 mouseClick(image0);
28 tryCompare(overlay, "visible", true);
29@@ -117,6 +117,7 @@
30 }
31
32 function test_overlayOpenCorrectImage(data) {
33+ var overlayListView = findChild(overlay, "overlayListView");
34 var image = findChild(imageGallery, "previewImage" + data.index);
35 mouseClick(image);
36 tryCompare(overlay, "visible", true);
37
38=== modified file 'tests/qmltests/Dash/tst_Card.qml'
39--- tests/qmltests/Dash/tst_Card.qml 2016-02-11 13:13:31 +0000
40+++ tests/qmltests/Dash/tst_Card.qml 2016-04-13 08:16:30 +0000
41@@ -217,16 +217,16 @@
42
43 when: windowShown
44
45- property Item title: findChild(card, "titleLabel")
46- property Item subtitle: findChild(card, "subtitleLabel")
47- property var headerRow: findChild(card, "outerRow")
48- property var art: findChild(card, "artShape")
49- property Item artImage: findChild(card, "artImage")
50- property Item summary: findChild(card, "summaryLabel")
51- property Item background: findChild(card, "background")
52- property Item backgroundLoader: findChild(card, "backgroundLoader")
53- property Item backgroundImage: findChild(card, "backgroundImage")
54- property Item mascotImage: findChild(card, "mascotImage");
55+ property Item title: findChild(loader, "titleLabel")
56+ property Item subtitle: findChild(loader, "subtitleLabel")
57+ property var headerRow: findChild(loader, "outerRow")
58+ property var art: findChild(loader, "artShape")
59+ property Item artImage: findChild(loader, "artImage")
60+ property Item summary: findChild(loader, "summaryLabel")
61+ property Item background: findChild(loader, "background")
62+ property Item backgroundLoader: findChild(loader, "backgroundLoader")
63+ property Item backgroundImage: findChild(loader, "backgroundImage")
64+ property Item mascotImage: findChild(loader, "mascotImage");
65
66 function init() {
67 cardTool.components = Qt.binding(function() { return Helpers.update(JSON.parse(Helpers.defaultLayout), Helpers.tryParse(layoutArea.text, layoutError))['components']; });
68
69=== modified file 'tests/utils/modules/Unity/Test/UnityTestCase.qml'
70--- tests/utils/modules/Unity/Test/UnityTestCase.qml 2016-03-16 10:50:58 +0000
71+++ tests/utils/modules/Unity/Test/UnityTestCase.qml 2016-04-13 08:16:30 +0000
72@@ -50,8 +50,11 @@
73 this.getCurrentTimeMs = function() {return this.currentTimeMs}
74 }
75
76- // TODO This function can be removed altogether once we use Qt 5.5 which has the same feature
77+ // TODO This function can be removed altogether once we use Qt 5.7 which has the same feature
78 function mouseClick(item, x, y, button, modifiers, delay) {
79+ if (!item)
80+ qtest_fail("no item given", 1);
81+
82 if (button === undefined)
83 button = Qt.LeftButton;
84 if (modifiers === undefined)
85@@ -66,8 +69,11 @@
86 qtest_fail("window not shown", 2);
87 }
88
89- // TODO This function can be removed altogether once we use Qt 5.5 which has the same feature
90+ // TODO This function can be removed altogether once we use Qt 5.7 which has the same feature
91 function mouseDoubleClick(item, x, y, button, modifiers, delay) {
92+ if (!item)
93+ qtest_fail("no item given", 1);
94+
95 if (button === undefined)
96 button = Qt.LeftButton;
97 if (modifiers === undefined)
98@@ -82,8 +88,11 @@
99 qtest_fail("window not shown", 2)
100 }
101
102- // TODO This function can be removed altogether once we use Qt 5.5 which has the same feature
103+ // TODO This function can be removed altogether once we use Qt 5.7 which has the same feature
104 function mousePress(item, x, y, button, modifiers, delay) {
105+ if (!item)
106+ qtest_fail("no item given", 1);
107+
108 if (button === undefined)
109 button = Qt.LeftButton;
110 if (modifiers === undefined)
111@@ -98,8 +107,11 @@
112 qtest_fail("window not shown", 2)
113 }
114
115- // TODO This function can be removed altogether once we use Qt 5.5 which has the same feature
116+ // TODO This function can be removed altogether once we use Qt 5.7 which has the same feature
117 function mouseRelease(item, x, y, button, modifiers, delay) {
118+ if (!item)
119+ qtest_fail("no item given", 1);
120+
121 if (button === undefined)
122 button = Qt.LeftButton;
123 if (modifiers === undefined)
124@@ -121,6 +133,9 @@
125 // speed is in pixels/second
126 function mouseFlick(item, x, y, toX, toY, pressMouse, releaseMouse,
127 speed, iterations) {
128+ if (!item)
129+ qtest_fail("no item given", 1);
130+
131 pressMouse = ((pressMouse != null) ? pressMouse : true); // Default to true for pressMouse if not present
132 releaseMouse = ((releaseMouse != null) ? releaseMouse : true); // Default to true for releaseMouse if not present
133
134@@ -159,6 +174,9 @@
135
136 // Find an object with the given name in the children tree of "obj"
137 function findChild(obj, objectName) {
138+ if (!obj)
139+ qtest_fail("no obj given", 1);
140+
141 return findChildIn(obj, "children", objectName);
142 }
143
144@@ -168,11 +186,17 @@
145 // as this tree is much bigger and might contain stuff that goes
146 // away randomly.
147 function findInvisibleChild(obj, objectName) {
148+ if (!obj)
149+ qtest_fail("no obj given", 1);
150+
151 return findChildIn(obj, "data", objectName);
152 }
153
154 // Find a child in the named property
155 function findChildIn(obj, prop, objectName) {
156+ if (!obj)
157+ qtest_fail("no obj given", 1);
158+
159 var childs = new Array(0);
160 childs.push(obj)
161 while (childs.length > 0) {
162@@ -188,6 +212,9 @@
163 }
164
165 function findChildsByType(obj, typeName) {
166+ if (!obj)
167+ qtest_fail("no obj given", 1);
168+
169 var res = new Array(0);
170 for (var i in obj.children) {
171 var c = obj.children[i];
172@@ -235,6 +262,9 @@
173 }
174
175 function flickToYEnd(item) {
176+ if (!item)
177+ qtest_fail("no item given", 1);
178+
179 var i = 0;
180 var x = item.width / 2;
181 var y = item.height - units.gu(1);
182@@ -254,6 +284,9 @@
183
184 // speed is in pixels/second
185 function touchFlick(item, x, y, toX, toY, beginTouch, endTouch, speed, iterations) {
186+ if (!item)
187+ qtest_fail("no item given", 1);
188+
189 // Make sure the item is rendered
190 waitForRendering(item);
191
192@@ -313,10 +346,16 @@
193 // perform a drag in the given direction until the given condition is true
194 // The condition is a function to be evaluated after every step
195 function touchDragUntil(item, startX, startY, stepX, stepY, condition) {
196+ if (!item)
197+ qtest_fail("no item given", 1);
198+
199 multiTouchDragUntil([0], item, startX, startY, stepX, stepY, condition);
200 }
201
202 function multiTouchDragUntil(touchIds, item, startX, startY, stepX, stepY, condition) {
203+ if (!item)
204+ qtest_fail("no item given", 1);
205+
206 var root = fetchRootItem(item);
207 var pos = item.mapToItem(root, startX, startY);
208
209@@ -361,9 +400,17 @@
210 event.commit()
211 }
212
213- function touchMove(item, tox, toy) { multiTouchMove(0, item, tox, toy); }
214+ function touchMove(item, tox, toy) {
215+ if (!item)
216+ qtest_fail("no item given", 1);
217+
218+ multiTouchMove(0, item, tox, toy);
219+ }
220
221 function multiTouchMove(touchId, item, tox, toy) {
222+ if (!item)
223+ qtest_fail("no item given", 1);
224+
225 if (typeof touchId !== "number") touchId = 0;
226 var root = fetchRootItem(item)
227 var rootPoint = item.mapToItem(root, tox, toy)
228@@ -374,6 +421,9 @@
229 }
230
231 function touchPinch(item, x1Start, y1Start, x1End, y1End, x2Start, y2Start, x2End, y2End) {
232+ if (!item)
233+ qtest_fail("no item given", 1);
234+
235 // Make sure the item is rendered
236 waitForRendering(item);
237
238@@ -400,13 +450,21 @@
239 }
240
241 function fetchRootItem(item) {
242+ if (!item)
243+ qtest_fail("no item given", 1);
244+
245 if (item.parent)
246 return fetchRootItem(item.parent)
247 else
248 return item
249 }
250
251- function touchPress(item, x, y) { multiTouchPress(0, item, x, y, []); }
252+ function touchPress(item, x, y) {
253+ if (!item)
254+ qtest_fail("no item given", 1);
255+
256+ multiTouchPress(0, item, x, y, []);
257+ }
258
259 /*! \brief Release a touch point
260
261@@ -417,6 +475,9 @@
262 \param stationaryPoints An array of touchIds which are "already touched"
263 */
264 function multiTouchPress(touchId, item, x, y, stationaryPoints) {
265+ if (!item)
266+ qtest_fail("no item given", 1);
267+
268 if (typeof touchId !== "number") touchId = 0;
269 if (typeof x !== "number") x = item.width / 2;
270 if (typeof y !== "number") y = item.height / 2;
271@@ -432,7 +493,12 @@
272 event.commit()
273 }
274
275- function touchRelease(item, x, y) { multiTouchRelease(0, item, x, y, []); }
276+ function touchRelease(item, x, y) {
277+ if (!item)
278+ qtest_fail("no item given", 1);
279+
280+ multiTouchRelease(0, item, x, y, []);
281+ }
282
283 /*! \brief Release a touch point
284
285@@ -443,6 +509,9 @@
286 \param stationaryPoints An array of touchIds which are "still touched"
287 */
288 function multiTouchRelease(touchId, item, x, y, stationaryPoints) {
289+ if (!item)
290+ qtest_fail("no item given", 1);
291+
292 if (typeof touchId !== "number") touchId = 0;
293 if (typeof x !== "number") x = item.width / 2;
294 if (typeof y !== "number") y = item.height / 2;
295@@ -465,10 +534,16 @@
296 \param y The y coordinate of the tap, defaults to vertical center
297 */
298 function tap(item, x, y) {
299+ if (!item)
300+ qtest_fail("no item given", 1);
301+
302 multiTouchTap([0], item, x, y);
303 }
304
305 function multiTouchTap(touchIds, item, x, y) {
306+ if (!item)
307+ qtest_fail("no item given", 1);
308+
309 if (typeof touchIds !== "object") touchIds = [0];
310 if (typeof x !== "number") x = item.width / 2;
311 if (typeof y !== "number") y = item.height / 2;
312@@ -508,6 +583,8 @@
313 This effectively makes DirectionalDragAreas easier to fool.
314 */
315 function removeTimeConstraintsFromDirectionalDragAreas(item) {
316+ if (!item)
317+ qtest_fail("no item given", 1);
318
319 // use duck-typing to identify a DirectionalDragArea
320 if (item.removeTimeConstraints != undefined) {

Subscribers

People subscribed via source and target branches