[Interest] QTest::qWait Error

Lucas.Betschart at crypto.ch Lucas.Betschart at crypto.ch
Mon Mar 26 14:37:39 CEST 2012


Hi Lucas,

> I'm trying to write Unit Tests.
> Because I have to wait till some data arrived from network and a signal triggers, I want to use qWait.
>
> But everytime I use qWait I get this error, even when there is nothing but qWait in the code.
>
> QCOMPARE, QVERIFY etc are working,
> I have added testlib to my .pro file.
>
> Any ideas what I'm doing wrong?

The assertion indicates that your test program does not have an instance of the QCoreApplication class.  Most likely this means that you are using the QTEST_APPLESS_MAIN macro to generate the test program's main() or that you have written your own main() and it does not create a QCoreApplication.

You can propbably fix this by using the QTEST_MAIN macro to generate your main().

--
Jason


Thanks, replacing QTEST_APPLESS_MAIN with QTEST_MAIN works.



Next question:

I've got some test slots which should only trigger when the signal arrived.
How can I test this? I want to use them like they're normal test cases but that they don't get called automatically.
I want them to be shown as part of the result overview.


Looks like this:

private Q_SLOTS:
    void normaleTestCase();     //gets called automatically

public slots:
    void signalReceivedTest();  //only gets triggered by signal, so not part of the Qt Test evaluation

};

MFE_Protocol_Unit_Tests::MFE_Protocol_Unit_Tests(){
   QObject::connect(&connection,SIGNAL(click()),this,SLOT(signalReceivedTest()));
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120326/de4df937/attachment.html>


More information about the Interest mailing list