Sunday, October 28, 2007

Struggling to TDD a GUI application

CMake is one of the best build tools out there. It has a nice command line interface and comes with an even nicer GUI. Unfortunately the GUI is MFC based, which means you need a VC professional license to build it for windows and you can't use it in linux.

Since Trolltech released it's wonderful GUI framework Qt for windows open source development some time ago, I decided to combine my eagerness to learn TDDing GUI apps with my need for a nice cmake GUI - and to start developing qcmake.

The first priority for me was to learn how to TDD a GUI application. CMakeSetup, the MFC application qcmake should be able to replace, has a very simple single-window interface, so this should be the ideal playground to get an idea of the basic GUI testing problems.

Setting up the testing framework.


The first step to successful TDD is to set up a test environment where you can execute your tests with a single keystroke from within your development environment. I spent some time integrating Qt's testing framework qtestlib into ctest. Hitting F5 from my Visual Studio Express executes all the tests. If something goes wrong, the qtestlib framework prints the debug output into the Visual Studio output window. This way I can just click on the error message to find the offending code, or just enable a breakpoint step through my personal mess...

Top-Down or Bottom-Up - the duck's decision


The testing framework is ready and eagerly waiting for it's first real test. But somehow I don't know where to start. The options are quite simple: either the good ol' bottom-up approach, implementing one layer upon each other until I reach the top, or the top-down development 2.0 methodology where everything is faked or mocked, slicing the whole vegetable vertically until the feature is finished.

Since the top-down approach resembles the design-driven process the most (plus the running tests, minus some heavy documents) and Heusser & McMillan's presentation Interaction Based Testing at GTAC made my mouth water (I really like chocolate flakes), I thought I'd go for the top-down method.

My first user interface test


And finally my first test looks like this:

#include "QCMakeTest.h"
#include "QCMakeWidget.h"

#include <QtTest/QTestMouseEvent>

void QCMakeTest::shouldEmitConfigureSignalOnConfigurePressed()
{
QCMakeUi::QCMakeWidget* qCMake = new QCMakeUi::QCMakeWidget();
QSignalSpy configurePressed(qCMake, SIGNAL(configure()));
QTest::mousePress(qCMake->getConfigureButton(), Qt::LeftButton);
QCOMPARE(configurePressed.count(), 1);
}

QTEST_MAIN(QCMakeTest)
#include "QCMakeTest.moc"


That was a lot of work just to get started with a simple test and basically no functionality. Fortunately I have some TDD experience to build upon, and right now this experience tells me that the up-front effort will pay of in the short run due to not debugging a lot. Up-front effort, quicker development, isn't that what BDUF was all about? I'm curious where all this will lead me to...

3 comments:

  1. Not sure if you have tried using Squish since then, but if not, maybe it will help?

    http://www.froglogic.com/

    ReplyDelete
  2. I've as a last resort liked things like sand clocks, lava lamps, and the like to good of just dish out time staring at it as a cut of catharsis. In a route, it helps me with meditation, to mitigate lay stress and well-grounded fantasize about nothing. That's why since I was a kid, in place of of dolls and cars I've eternally at ease more of such pieces like sand clocks, lava lamps, harmonious boxes etc. So I was most enchanted when I start the 2-Laser + LED Inconsiderable Presentation Laser Top Gyroscope with Music Effects from DealtoWorld.com answerable to the Toys section. It's like a melodic caddy, a spinning head, and a moonlight verify all rolled into one. Which is spectacular entertainment! The gyroscope transfer concoct object of round a minute. The laser light pretension with accompanying music makes this gyroscope a pretty unequalled bauble that my friends get also been most amused with.

    My dogs are also nice-looking curious nearly the laser gyroscope I got from DealtoWorld.com. They evermore follow the gyroscope as it spins, although at earliest they kept barking at the laser light show, and also because it produces music. But after they got worn it, they've stopped barking but just save up following the gyroscope whenever I start spinning it. Kids are also pretty amused nearby it. On occasion it's moral to possess entertaining toys about the lineage so that you can go away the diminutive on while the kids are being amused or playing with it while you open to get up viands or receive changed. The gyroscope is one such fool with with this purpose.

    The gyroscope I bought from DealtoWorld.com has a dragon as a map on it, and produces a dainty show with red, obscene, and unripened colours. Take a look at the pictures I've uploaded of the gyroscope with laser light show. The music produced from the gyroscope is not that expert but decorous enough to consider any chic guest to the house. The gyroscope is red and black, making it look exceedingly imperturbable, and somewhat macho with that dragon imprint.

    The music light make clear gyroscope runs on 6 LR44 batteries, which are replaceable anyway. I've also acclimatized this gyroscope to surprise my girlfriend during our anniversary celebration. I did the cheesy thing of decorating the hotel elbow-room with roses and when I led her in, I started up the gyroscope as correctly so that the laser brighten register produces a ideal effect. I also had some battery operated candles so all the understanding effects created a slightly romanticist atmosphere. She loved it, by the way, to my relief. I also bought the candles from DealtoWorld.com. These days it seems to be my non-performance shopping placement for all gifts and ideas in support of romantic occasions.

    Since Christmas is coming, this laser radiance make clear gyroscope can possibly be a momentous Christmas give-away looking for the toddler or in spite of the favoured! Alternatively, the gyroscope can simply be a kindly totalling to the ordinary Christmas decorations. I can imagine placing it adjoining the Christmas tree and perhaps spinning it when guests succeed in the house. Looks like DealtoWorld.com is getting my function anyway again!

    ReplyDelete
  3. Most major credit cards won't allow transactions with offshore casinos as they function illegally in the us Never a dull second in video poker.We prodded Coach Kitty 1xbet korea to reveal a few of her favorite video poker bars and machines, and she was up to as} the challenge. Don’t Chase the Royal Flush – The payout is huge, however it solely hits once as} every forty,000 palms or so.

    ReplyDelete