Qtmock - Interesting thing, but I can’t figure it out. Has anybody tried it?

  • I am into test-driven development and for was looking for a Qt compatible mocking framework (something to simulate e.g. file reads without having to write full blown QFile simulation myself).

    I found an interesting branch called qtmock here - https://qt.gitorious.org/~niandong/qt/niandongs-qttools/commits/qtmock

    It compiles and demo does work, but I can't figure it out further :)
    This mock framework is heavily based on macros so trying to understand what's generated automatically and what's written by hand isn't easy. My helloworldish trials failed as well.

    Has anybody looked at it?
    I would appreciate if somebody experienced could have a look or maybe even create a helloworldish example with it.

  • hi

    im in a worser situation that you. how where you able to build it? i opened the qttools.pro file and tried to build it but it failed since it coudlnt find qfunctions_h.h in a "private" folder. what project did you build and what test did you do? im trying to mock the QNAM for a larger project

  • Yep, I am building it fine with the usual qmake-make. Framework itself is not well documented, but works more or less.

    However, I don't touch qttools.pro you mention at all. I cloned only qtmock part of it (inside qtestlib). I am not 100% sure if I modified anything to make it compile in a stand-alone way, but even if I did it definitely was something simple.

  • so you imported that part of it and just rebuild your qt? im really new to building things on windows and my qt is built to fit with visual studio so i cant really rebuild it without it taking about 3 hours. could you please specify what you mean?

  • I made qtmock just one of subprojects of my big project (an engine library, app, a couple of external libraries that are built as a part of the project, a number of automatic tests).

    So the library is built as if it was one of the libraries I've written myself.

  • ah that makes sense. yeah i tried to build the qtmock.pro file and that worked fine. i really hope this is the answer to my qtprayes. absolutly hate that the QNAM doesnt have any virtual functions so that i can produce a fake version of it. ...

  • been looking at the demos and it seem pretty clear to me. in the NetworkTest you just take a QNAM and then define its behaviour. the wierd thing that I dont understand is how those settings gets transfered since there's no injection taking place what i can see. Just like you set how the QNAM should act and then in any object that you create where u have a QNAM it will act the way we wanted to.

  • What they do in the examples is that they mock the whole QNAM library, i.e. create a stand-alone separate library that looks totally like QNAM, implements the same interfaces, but instead of the real QNAM implementation all the methods just pass the ball to the mocking framework as in the following:
    QNetworkCookie &QNetworkCookie::operator=(const QNetworkCookie &other)
    QVector<QGenericArgument> args;
    args.append(Q_ARG(const QNetworkCookie &, other));

    QTMOCK_METHOD_DOACTIONS("QNetworkCookie", "operator=", QRET_REF(QNetworkCookie), &args, NULL);


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.