Test-Driving QMLArtem MarchenkoMarch 15, 2011
Artem MarchenkoProduct Manager, Researcher, CoachProduct Manager shipping multi-hundred MEur productsScrum Master, Practitioner, Product Owner and CoachThree times Forum Nokia ChampionPrivate entrepreneurAvailable for hirehttp://fi.linkedin.com/in/artemmarchenko
Test-Driven Development. Or just testing QMLWhat TDD is aboutGetting startedSimple Synchronous testSimulating mouse and keyboard actionsAsynchronous tests (verifying callbacks)Data-driven testsCurrent limitationsQ&As
Test-Driven DevelopmentRemove duplication
Example of a QML-code developed via TDD
Getting started 1(3)git clone git://gitorious.org/qt-labs/qtest-qml.gitCloning 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/qmakeqtest-qml.promakemake installmake docsmake checkProject page: http://qt.gitorious.net/qt-labs/qtest-qml
Getting started 2(3)Create the simplest test in your project
Getting started 3(2)And a script that runs the test: runTests.sh in this case#!/bin/bashclear/Users/artem/QtSDK/Desktop/Qt/471/gcc/bin/QMLViewer.app/Contents/MacOS/QMLViewer tst_tddCalculator2.qml
Simple synchronous tests
UI level: simulating mouse click
UI level: simulating touch and drag
Asynchronous testing: tryCompare
Asynchronous testing: SignalSpy
Data-driven tests
Current LimitationsInstallation doesn’t install qtest-qml to QtCreator 2.1 Tech PreviewNot that you would need it for TDD, but if you are into “just testing” already written code, debugger may be helpfulBug: only one TestCase is allowed: http://bugreports.qt.nokia.com/browse/QTBUG-17200It makes init() and cleanup nearly uselessOrganize your test structure by your own toolsSmall difficulties comparing built-in classes (e.g. color)toString() helps most of the time
Current limitationsVery strange errors when object/property can be accessed e.g. because of a typoSegmentation faults, sometimes even “file not found”In 95% of cases that is a typo or an attempt to access a non-public property
Current limitationsSignalSpy can only count It cannot examine the signal arguments or the state of other objectsBenchmarking is a part of a qtest-qml, but doesn’t work properlyThat 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 runnersThough you can certainly, embed a “run tests” button right into your application
Thank youQ&As timeYou can find these slides at http://agilesoftwaredevelopment.com/tags/tdd

Test driving QML

  • 1.
  • 2.
    Artem MarchenkoProduct Manager,Researcher, CoachProduct Manager shipping multi-hundred MEur productsScrum Master, Practitioner, Product Owner and CoachThree times Forum Nokia ChampionPrivate entrepreneurAvailable for hirehttp://fi.linkedin.com/in/artemmarchenko
  • 3.
    Test-Driven Development. Orjust testing QMLWhat TDD is aboutGetting startedSimple Synchronous testSimulating mouse and keyboard actionsAsynchronous tests (verifying callbacks)Data-driven testsCurrent limitationsQ&As
  • 4.
  • 5.
    Example of aQML-code developed via TDD
  • 6.
    Getting started 1(3)gitclone git://gitorious.org/qt-labs/qtest-qml.gitCloning 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/qmakeqtest-qml.promakemake installmake docsmake checkProject page: http://qt.gitorious.net/qt-labs/qtest-qml
  • 7.
    Getting started 2(3)Createthe simplest test in your project
  • 8.
    Getting started 3(2)Anda script that runs the test: runTests.sh in this case#!/bin/bashclear/Users/artem/QtSDK/Desktop/Qt/471/gcc/bin/QMLViewer.app/Contents/MacOS/QMLViewer tst_tddCalculator2.qml
  • 9.
  • 10.
  • 11.
    UI level: simulatingtouch and drag
  • 12.
  • 13.
  • 14.
  • 15.
    Current LimitationsInstallation doesn’tinstall qtest-qml to QtCreator 2.1 Tech PreviewNot that you would need it for TDD, but if you are into “just testing” already written code, debugger may be helpfulBug: only one TestCase is allowed: http://bugreports.qt.nokia.com/browse/QTBUG-17200It makes init() and cleanup nearly uselessOrganize your test structure by your own toolsSmall difficulties comparing built-in classes (e.g. color)toString() helps most of the time
  • 16.
    Current limitationsVery strangeerrors when object/property can be accessed e.g. because of a typoSegmentation faults, sometimes even “file not found”In 95% of cases that is a typo or an attempt to access a non-public property
  • 17.
    Current limitationsSignalSpy canonly count It cannot examine the signal arguments or the state of other objectsBenchmarking is a part of a qtest-qml, but doesn’t work properlyThat 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 runnersThough you can certainly, embed a “run tests” button right into your application
  • 18.
    Thank youQ&As timeYoucan find these slides at http://agilesoftwaredevelopment.com/tags/tdd

Editor's Notes

  • #10 Adding numbers continuously – property bindingChange color when result is over 1000 => .toString() when comparing complex built-in objectsMove to states. Change the default color
  • #11 Increase font on mouseClick – when:windowShown