I just noticed that even on a fresh new project, Qt Unit Test writes everything twice in the Application Output pane, in different colors - first in magenta, then in black. I assume this is because it writes to both stdout and stderr.
This happens on Qt 4.8 but not on Qt 5.2.2. In Qt 5.2.2 only the black text is printed, as it should.
As an example, for a unit test project that contains only this test:
void Untitled15Test::testCase1()
{
QVERIFY2(false, "Failure");
}
The output is this (I use a screenshot so the colors show):
Is there a way to turn off this behavior? Is it a bug in Qt4?
After some searching on the Qt Bug Tracker site I found out it is indeed a bug. I found the bug report mentioning it:
Description If one turns off the "run on terminal" option on Windows, qDebug's output will be printed twice in the application output pane. This is due to qDebug using OutputDebugString and stderr to output it's messages. To solve this we could do one of these items: Display the OutputDebugString stream and stderr in different panes if "run on terminal" is off. Provide a checkbox to hide the OutputDebugString stream in the application output pane. Prevent QDebug from using OutputDebugString and stderr. Maybe using an environment variable that is set by Qt Creator.
I think that this happens because QTestLib uses CONFIG += console
, while at the same time turning off the "Run in terminal" checkbox, thus triggering this bug.