Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTest Crash: Requested testdata not available, check your _data function
QtWS25 Last Chance

QTest Crash: Requested testdata not available, check your _data function

Scheduled Pinned Locked Moved Solved General and Desktop
qt6qt6.4.1qtest
3 Posts 2 Posters 602 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kevin470
    wrote on 2 Dec 2022, 14:42 last edited by Kevin470 12 Feb 2022, 14:49
    #1

    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 function static int add_function(int a, int b); which just returns an added value of 'a' and 'b'"

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 2 Dec 2022, 14:51 last edited by Christian Ehrlicher 12 Feb 2022, 14:53
      #2

      'firstNumber' != 'FirstNumber'
      See https://doc.qt.io/qt-6/qtest.html#QFETCH

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      K 1 Reply Last reply 2 Dec 2022, 14:52
      2
      • C Christian Ehrlicher
        2 Dec 2022, 14:51

        'firstNumber' != 'FirstNumber'
        See https://doc.qt.io/qt-6/qtest.html#QFETCH

        K Offline
        K Offline
        Kevin470
        wrote on 2 Dec 2022, 14:52 last edited by
        #3

        @Christian-Ehrlicher Thank you so much. That is a very rookie mistake from my end. Thanks again

        1 Reply Last reply
        2

        1/3

        2 Dec 2022, 14:42

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved