Details
-
Bug
-
Resolution: Duplicate
-
Not Evaluated
-
None
-
5.10.1
-
None
Description
Sample code to reproduce the issue :
TestExample.h
#ifndef TESTEXAMPLE_H #define TESTEXAMPLE_H #include <QDebug> #include <QObject> #include <QtTest/QtTest> class TestExample : public QObject { Q_OBJECT private slots: void initTestCase(); void cleanupTestCase(); void testWithoutBenchmark(); void testWithBenchmark(); private: long long _value; long long _benchmarkValue; }; #endif // TESTEXAMPLE_H
TestExample.cpp
#include "TestExample.h"
void TestExample::initTestCase() {
_value=0;
_benchmarkValue=0;
}
void TestExample::cleanupTestCase() {
QVERIFY(_benchmarkValue > 0);
QVERIFY(_value == 2);
}
void TestExample::testWithoutBenchmark() {
_value++;
qDebug() << QString::number(_value);
QVERIFY(_value == 1);
}
void TestExample::testWithBenchmark() {
_value++;
qDebug() << QString::number(_value);
QVERIFY(_value == 2);
QBENCHMARK {
_benchmarkValue++;
}
}
QTEST_APPLESS_MAIN(TestExample)
Expected behavior : both tests passes, and each test is called only once, the code inside the QBENCHMARK brackets is called multiple times.
Observed behavior : testWithoutBenchmark passes, testWithBenchmark fails because it's called multiple times. Remove the QVERIFY of testWithBenchmark to see how many times the test slot is called though the qDebug output.
Same issue occur with QBENCHMARK_ONCE, resulting in even more unexpected result as the code inside QBNECHMARK_ONCE is executed several times when it should run only one time.