QTest Crash: Requested testdata not available, check your _data function
-
Hello,
As mentioned in my previous post "https://forum.qt.io/topic/141202/qt6-cmake-undefined-reference-to-winmain", I am learning QTest and CMake with QtCreator.
I recently upgraded Qt and Qt Creator to Qt 6.4.1and QtCreator 9.
Is there a possibility that there could be a bug with the latest version of either one of them since a sample QTest Module crashes when a Data Driven Unit Test is run.
The Sample Code I have for testing:#include <QObject> #include <QTest> #include "../adder.hpp" class TestAdder : public QObject { private: Q_OBJECT private slots: void test1_data(); void test1(); }; void TestAdder::test1_data() { QTest::addColumn<int>("FirstNumber"); QTest::addColumn<int>("SecondNumber"); QTest::newRow("FirstTest") << 1 << 7; QTest::newRow("SecondTest") << 8 << 11; } void TestAdder::test1() { QFETCH(int, firstNumber); QFETCH(int, secondNumber); QCOMPARE(Adder::add_function(firstNumber,secondNumber), (firstNumber + secondNumber)); } QTEST_MAIN(TestAdder); #include "test_adder.moc"
The Fatal Error it throws:
FAIL Executing test case TestAdder Qt version: 6.4.1 Qt build: Qt 6.4.1 (x86_64-little_endian-llp64 shared (dynamic) release build; by GCC 11.2.0) QTest version: 6.4.1 PASS Executing test function initTestCase PASS TestAdder::initTestCase Execution took 0.6662 ms. FAIL Executing test function test1 FAIL Data tag: First Try FATAL QFETCH: Requested testdata 'firstNumber' not available, check your _data function. FAIL TestAdder::test1 (First Try) Received a fatal error. Execution took 0.0497 ms. Test execution took 0.7977 ms. FATAL Test executable crashed. FATAL Test for project "adder" crashed. Command line: C:\Users\UserName\Documents\Qt_Projects\build-cmake_with_tests-Desktop_Qt_6_4_1_MinGW_64_bit-Debug\tests\adder.exe -xml test1 Run configuration: "adder"
"Edit: Tried with
QTest::addRow()
as well. Same issue.
The Adder Class has one static public functionstatic int add_function(int a, int b);
which just returns an added value of 'a' and 'b'" -
'firstNumber' != 'FirstNumber'
See https://doc.qt.io/qt-6/qtest.html#QFETCH -
@Christian-Ehrlicher Thank you so much. That is a very rookie mistake from my end. Thanks again