I try to do that unit test results are printed in jenkins console. But I can not do. I am thinking that jenkins build console can not print qDebug. And I tried it can not print qdebug. But std::cout is working. How can I proceed?
Thank you. I tried that you said. But It can not work. It gives error. error: C3861: 'qInstallMsgHandler': identifier not found
//! [0]
#include <QtTest/QtTest>
#include <qapplication.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <QDebug>
void myMessageOutput(QtMsgType type, const char *msg)
{
switch (type) {
case QtDebugMsg:
fprintf(stderr, "Debug: %s\n", msg);
break;
case QtWarningMsg:
fprintf(stderr, "Warning: %s\n", msg);
break;
case QtCriticalMsg:
fprintf(stderr, "Critical: %s\n", msg);
break;
case QtFatalMsg:
fprintf(stderr, "Fatal: %s\n", msg);
abort();
}
}
class TestQString: public QObject
{
Q_OBJECT
public:
TestQString(){
qInstallMsgHandler(myMessageOutput);
}
private slots:
void toUpper();
};
//! [0]
//! [1]
void TestQString::toUpper()
{
QString str = "Hello";
QCOMPARE(str.toUpper(), QString("HELLO"));
qDebug() << "hello";
std::cout << "Hello, world!\n\n";
}
//! [1]
//! [2]
QTEST_MAIN(TestQString)
#include "testqstring.moc"
//! [2]