Test driving-qml

18
Test-Driving QML Artem Marchenko March 15, 2011

Transcript of Test driving-qml

Page 1: Test driving-qml

Test-Driving QML

Artem Marchenko

March 15, 2011

Page 2: Test driving-qml

Artem Marchenko

http://fi.linkedin.com/in/artemmarchenko

Page 3: Test driving-qml

Test-Driven Development. Or just testing QML

• What TDD is about

• Getting started

• Simple Synchronous test

• Simulating mouse and keyboard actions

• Asynchronous tests (verifying callbacks)

• Data-driven tests

• Current limitations

• Q&As

Page 4: Test driving-qml

Test-Driven Development

Page 5: Test driving-qml

Example of a QML-code developed via TDD

Page 6: Test driving-qml

Getting started 1(3)

git clone git://gitorious.org/qt-labs/qtest-qml.git

Cloning into qtest-qml...

remote: Counting objects: 888, done.

remote: Compressing objects: 100% (669/669), done.

remote: Total 888 (delta 445), reused 393 (delta 187)

Receiving objects: 100% (888/888), 411.11 KiB, done.

Resolving deltas: 100% (445/445), done.

cd qtest-qml/

qmake qtest-qml.pro

make

make install

make docs

make check

Project page: http://qt.gitorious.net/qt-labs/qtest-qml

Page 7: Test driving-qml

Getting started 2(3)

• Create the simplest test in your project

Page 8: Test driving-qml

Getting started 3(2)

• And a script that runs the test: runTests.sh in this case

#!/bin/bash

clear

/Users/artem/QtSDK/Desktop/Qt/471/gcc/bin/QMLViewer.app/Contents/MacOS/QMLViewer tst_tddCalculator2.qml

Page 9: Test driving-qml

Simple synchronous tests

Page 10: Test driving-qml

UI level: simulating mouse click

Page 11: Test driving-qml

UI level: simulating touch and drag

Page 12: Test driving-qml

Asynchronous testing: tryCompare

Page 13: Test driving-qml

Asynchronous testing: SignalSpy

Page 14: Test driving-qml

Data-driven tests

Page 15: Test driving-qml

Current Limitations

• Installation doesn’t install qtest-qml to QtCreator2.1 Tech Preview– Not that you would need it for TDD, but if you are into

“just testing” already written code, debugger may be helpful

• Bug: only one TestCase is allowed: http://bugreports.qt.nokia.com/browse/QTBUG-17200

– It makes init() and cleanup nearly useless

– Organize your test structure by your own tools

• Small difficulties comparing built-in classes (e.g. color)– toString() helps most of the time

Page 16: Test driving-qml

Current limitations

• Very strange errors when object/property can be accessed e.g. because of a typo

• Segmentation faults, sometimes even “file not found”

• In 95% of cases that is a typo or an attempt to access a non-public property

Page 17: Test driving-qml

Current limitations

• SignalSpy can only count – It cannot examine the signal arguments or the state of

other objects

• Benchmarking is a part of a qtest-qml, but doesn’t work properly– That is I failed to make it run for a given amount of

times (most of the time it does just a single run)

• No built-in device test runners– Though you can certainly, embed a “run tests” button

right into your application

Page 18: Test driving-qml

Thank you

Q&As time

You can find these slides at http://agilesoftwaredevelopment.com/tags/tdd