How to see QTest results
I am using QTest from Qt 5.3.2 to do some unit tests for a class. I am using VS2013 Express to build a tester. The VS project file is generated from a .pro file using qmake. To run tests, I added QTEST_MAIN to the source file.
The project is being built and the tester is working fine. However, I am having trouble viewing the results (e.g. PASS output). When the test window is run, all test output is displayed. If the test is complete, the console window closes immediately and I cannot see what it displayed. Especially I do not see that some tests have failed.
I assume QTest uses stdout as its default output pipe. So I tried the VS debugger option "Redirect stdout to output window", but it had no effect.
So how is this supposed to work?
Should the test output actually go to the recently opened console window? Then why doesn't it stay open? Or should all test output go to the VS debugger output pane? Is there a way to redirect the output?
source to share
Have you got it installed Visual Studio Add-in
for your version Visual Studio
? If not, you must download it from qt-project.org/downloads .
I did a simple qt test and imported the file *.pro
inside Visual Studio
and ran the test; everything works fine for me and the window stays open showing a summary of the tests:
I recommend writing an example , importing it into Visual Studio using Visual Studio Add-in
and comparing the project settings. Most likely, you need to change the flag to keep the window open.
It is also possible that you need to install Console (/SUBSYSTEM:CONSOLE)
linker. Right click on the project, go to project Properties
, select Configuration Properties>Linker>System
. For a property Subsystem
in the right pane, click the drop-down list in the right column. Now select Console (/SUBSYSTEM:CONSOLE)
and repeat the test ( Ctrl+F5and NOT only F5) (1).
If you run the test in mode Debug
(i.e. by clicking F5), your window will not remain open. If you want it to remain open, you need to add a call getch()
to your test destructor, and when your test ends, the window will remain waiting for input (for example Enter
):
For my test code:
#include <QtTest/QtTest>
#include <conio.h>
class TestQString: public QObject
{
Q_OBJECT
private slots:
void toUpper();
public:
~TestQString()
{
getch();
}
};
void TestQString::toUpper()
{
QString str = "Hello";
QCOMPARE(str.toUpper(), QString("HELLO"));
}
QTEST_MAIN(TestQString)
#include "testqstring.moc"
source to share