For all those that would like to see what is actually happening during their GUI tests while using QtTestLib. All you have to do is show the widget and start an event loop at the points you want to see or after some sequence has happened. Note that you can interact with the widget during the event loops and change the test results. This could be used to auto replay a sequence you find yourself doing over and over during testing or create an executable demo....simply drop the following code into the two files indicated and load in QtCreator or build and run from the command line as you prefer.
tst_hello.cpp
#include <QtGui>
#include <QtTest/QtTest>
/**
* Provides a Hello Qt World Gui/Integration test.
*/
{
Q_OBJECT
void eventLoop(const int msec);
private slots:
void testGUI();
};
/**
* The event loop.
*/
void tst_Hello::eventLoop(const int msec)
{
QObject::connect(&timer,
SIGNAL(timeout
()),
&loop,
SLOT(quit
()));
timer.setSingleShot(true);
timer.start(msec);
loop.exec();
}
/**
* The test method.
*/
void tst_Hello::testGUI()
{
lineEdit.show();
eventLoop(1200);
QTest::keyClicks(&lineEdit, "Hello Qt World");
eventLoop(1200);
QCOMPARE
(lineEdit.
text(),
QString("Hello Qt World"));
}
QTEST_MAIN(tst_Hello)
#include "tst_hello.moc"
#include <QtGui>
#include <QtTest/QtTest>
/**
* Provides a Hello Qt World Gui/Integration test.
*/
class tst_Hello : public QObject
{
Q_OBJECT
void eventLoop(const int msec);
private slots:
void testGUI();
};
/**
* The event loop.
*/
void tst_Hello::eventLoop(const int msec)
{
QEventLoop loop;
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
timer.setSingleShot(true);
timer.start(msec);
loop.exec();
}
/**
* The test method.
*/
void tst_Hello::testGUI()
{
QLineEdit lineEdit;
lineEdit.show();
eventLoop(1200);
QTest::keyClicks(&lineEdit, "Hello Qt World");
eventLoop(1200);
QCOMPARE(lineEdit.text(), QString("Hello Qt World"));
}
QTEST_MAIN(tst_Hello)
#include "tst_hello.moc"
To copy to clipboard, switch view to plain text mode
GuiTest.pro
TEMPLATE = app
TARGET = guitest
SOURCES += tst_hello.cpp
QT += testlib
TEMPLATE = app
TARGET = guitest
SOURCES += tst_hello.cpp
QT += testlib
To copy to clipboard, switch view to plain text mode
Bookmarks