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::fetchData(): "Test data requested, but no testdata available."
Forum Updated to NodeBB v4.3 + New Features

QTest::fetchData(): "Test data requested, but no testdata available."

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 4.0k Views 2 Watching
  • 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.
  • L Offline
    L Offline
    llarse
    wrote on 9 Mar 2017, 19:54 last edited by
    #1

    Hi

    I'm using Qt 5.7.1, on Ubuntu
    I was following this tutorial : http://doc.qt.io/qt-5/qttestlib-tutorial2-example.html
    But i block on this problem, all my google skills haven't be able to find a solution in forums.

    This is my code.

    #include <QtTest>
    
    class TestQString: public QObject
    {
    	Q_OBJECT
    
    private slots:
    	void toUpper();
    	void toUpper_data();
    };
    
    void TestQString::toUpper_data()
    {
    	QTest::addColumn<QString>("input");
    	QTest::addColumn<QString>("output");
    
    	QTest::newRow("all lower") << "hello" << "HELLO";
    	QTest::newRow("mixed") << "Hello" << "HELLO";
    	QTest::newRow("all upper") << "HELLO" << "HELLO";
    }
    
    void TestQString::toUpper()
    {
    	QFETCH(QString, input);
    	QFETCH(QString, output);
    	QCOMPARE(input.toUpper(), output);
    }
    
    QTEST_MAIN(TestQString)
    #include "moc_TestQString.cpp"
    

    I get this error:

    ********* Start testing of TestQString *********
    Config: Using QtTest library 5.7.1, Qt 5.7.1 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 6.3.0 20170124)
    PASS   : TestQString::initTestCase()
    QFATAL : TestQString::toUpper() ASSERT failure in QTest::fetchData(): "Test data requested, but no testdata available.", file qtestcase.cpp, line 1018
    FAIL!  : TestQString::toUpper() Received a fatal error.
       Loc: [Unknown file(0)]
    Totals: 1 passed, 1 failed, 0 skipped, 0 blacklisted, 0ms
    ********* Finished testing of TestQString *********
    Aborted (core dumped)
    

    By break stepping into the Debug execution, i found out that toUpper_data() was never called. That's why there is no "testdata available" since a data table was never created.

    Why does the toUpper_data() was not called by the Main generated by the Macro : QTEST_MAIN ?

    Thank you.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 9 Mar 2017, 21:24 last edited by
      #2

      Hi and welcome to devnet,

      Are you using qmake to manage your project ?

      I've just tested it on macOS and it's working fine. Just had to change the name of the included .moc file in order to build this properly though.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • L Offline
        L Offline
        llarse
        wrote on 9 Mar 2017, 22:55 last edited by llarse 3 Sept 2017, 22:57
        #3

        Hi,

        I'm not using qmake but cmake.
        Here is a short copy of the CMakeLists.txt

        cmake_minimum_required(VERSION 3.7.2)
        project(ocs-gui)
        
        set(CMAKE_INCLUDE_CURREND_DIR on)
        set(CMAKE_BUILD_TYPE Debug)
        
        find_package(Qt5 REQUIRED COMPONENTS Widgets Core Gui Test)
        if(Qt5_FOUND)
           message("Qt5 found")
        endif()
        
        set(test_files
            test/TestQString.cpp
        )
        
        set(headers_test_files
            test/TestQString.h
        )
        
        qt5_wrap_cpp(header_test_files_moc ${headers_test_files})
        
        add_definitions(${QT_DEFINITIONS})
        
        include_directories(${CMAKE_CURRENT_BINARY_DIR} include)
        
        add_executable(ocs-gui-test ${source_files} ${header_files_moc} ${form_headers_files} ${test_files} ${test_files_headers})
        target_compile_features(ocs-gui-test PRIVATE cxx_range_for)
        link_directories(test)
        target_link_libraries(ocs-gui-test Qt5::Widgets Qt5::Test)
        

        Could you copy the content of your .pro ?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 10 Mar 2017, 07:55 last edited by
          #4
          QT += widgets testlib
          
          SOURCES = testqstring.cpp
          

          And I've changed the last line for

          #include "testqstring.moc"
          

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          L 1 Reply Last reply 10 Mar 2017, 15:46
          0
          • S SGaist
            10 Mar 2017, 07:55
            QT += widgets testlib
            
            SOURCES = testqstring.cpp
            

            And I've changed the last line for

            #include "testqstring.moc"
            
            L Offline
            L Offline
            llarse
            wrote on 10 Mar 2017, 15:46 last edited by
            #5

            @SGaist

            Alright, problems came from my CMakeLists.txt.
            Thank for helping me out. With your post, i've stoped looking into the Qt Version or into the Qt code to see if something when wrong.

            My guess is that the qt5_wrap_cpp() wasn't generating good moc files since the Q_OBJECT was declared inside the cpp.

            Here is a good CMakeLists.txt

            cmake_minimum_required(VERSION 3.7.2)
            project(test-app)
            
            set(CMAKE_INCLUDE_CURREND_DIR on)
            set(CMAKE_BUILD_TYPE Debug)
            
            find_package(Qt5 REQUIRED COMPONENTS Widgets Core Gui Test)
            if(Qt5_FOUND)
               message("Qt5 found")
            endif()
            
            set(test_files
                test/TestQString.cpp
            )
            
            set(headers_test_files
                test/TestQString.h
            )
            
            qt5_wrap_cpp(header_test_files_moc ${headers_test_files})
            add_definitions(${QT_DEFINITIONS})
            include_directories(${CMAKE_CURRENT_BINARY_DIR} include)
            add_executable(test-app ${test_files} ${test_files_headers})
            target_compile_features(test-app PRIVATE cxx_range_for)
            link_directories(test)
            target_link_libraries(test-app Qt5::Widgets Qt5::Test)
            

            Thank you !
            LAL

            1 Reply Last reply
            1
            • Z Offline
              Z Offline
              zipzhang
              wrote on 28 Apr 2017, 07:51 last edited by
              #6

              I'm using qmake, I got this error too. After I deleted the build directory and run qmake again, it worked.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Surendranath
                wrote on 15 Sept 2020, 18:44 last edited by
                #7

                For this i have the same error getting. please check it where should i wrong?

                testcalculator cpp file

                #include <QtTest>

                #include "Maths.hpp"

                class TestCalculator : public QObject
                {
                Q_OBJECT

                private slots:
                void test_case1();
                void testNumbers();

                };

                void TestCalculator::test_case1()
                {
                QTest::addColumn<int>("a");
                QTest::addColumn<int>("b");
                QTest::addColumn<int>("expectedAddition");
                QTest::addColumn<int>("expectedSubstraction");
                QTest::addColumn<int>("expectedMultiplication");

                QTest::newRow("all zero") << 0 << 0 << 0 << 0 << 0 ;
                QTest::newRow("same number") << 10 << 10 << 20 << 0 << 100 ;
                QTest::newRow("different number") << 10 << 5 << 15 << 5 << 50 ;
                QTest::newRow("1 +ve, 1 -ve number") << 10 << -5 << 5 << 15 << -50 ;
                QTest::newRow("-ve numbers") << -5 << -10 << -15 << 5 << 50;
                

                }

                void TestCalculator::testNumbers()
                {
                QFETCH(int, a);
                QFETCH(int, b);
                QFETCH(int, expectedAddition);
                QFETCH(int, expectedSubstraction);
                QFETCH(int, expectedMultiplication);

                Maths objNumber;
                
                int addResult=objNumber.add(a,b);
                qDebug()<< a;
                qDebug()<< b;
                qDebug()<< expectedAddition;
                qDebug()<< addResult;
                
                QCOMPARE(addResult, expectedAddition);
                
                int diffResult=objNumber.subtract(a,b);
                qDebug()<< a;
                qDebug()<< b;
                qDebug()<< expectedSubstraction;
                qDebug()<< diffResult;
                QCOMPARE(diffResult, expectedSubstraction);
                
                int mulResult=objNumber.multiplication(a,b);
                qDebug()<< a;
                qDebug()<< b;
                qDebug()<< expectedMultiplication;
                qDebug()<< mulResult;
                QCOMPARE(mulResult, expectedMultiplication);
                

                }

                QTEST_APPLESS_MAIN(TestCalculator)

                #include "tst_testcalculator.moc"

                ********* Start testing of TestCalculator *********
                Config: Using QtTest library 5.12.7, Qt 5.12.7 (x86_64-little_endian-llp64 shared (dynamic) debug build; by GCC 7.3.0)
                PASS : TestCalculator::initTestCase()
                PASS : TestCalculator::test_case1()
                QFATAL : TestCalculator::testNumbers() ASSERT failure in QTest::fetchData(): "Test data requested, but no testdata available.", file qtestcase.cpp, line 1167
                FAIL! : TestCalculator::testNumbers() Received a fatal error.
                Unknown file(0) : failure location
                Totals: 2 passed, 1 failed, 0 skipped, 0 blacklisted, 1ms
                ********* Finished testing of TestCalculator *********
                00:05:38: The program has unexpectedly finished.
                00:05:38: The process was ended forcefully.

                This is the testcalculator.pro file

                QT += testlib
                QT -= gui

                CONFIG += qt console warn_on depend_includepath testcase
                CONFIG -= app_bundle

                TEMPLATE = app

                SOURCES += tst_testcalculator.cpp
                Maths.cpp

                HEADERS +=
                Maths.hpp

                Thank you,
                Surendranath

                S 1 Reply Last reply 16 Sept 2020, 07:35
                0
                • S Surendranath
                  15 Sept 2020, 18:44

                  For this i have the same error getting. please check it where should i wrong?

                  testcalculator cpp file

                  #include <QtTest>

                  #include "Maths.hpp"

                  class TestCalculator : public QObject
                  {
                  Q_OBJECT

                  private slots:
                  void test_case1();
                  void testNumbers();

                  };

                  void TestCalculator::test_case1()
                  {
                  QTest::addColumn<int>("a");
                  QTest::addColumn<int>("b");
                  QTest::addColumn<int>("expectedAddition");
                  QTest::addColumn<int>("expectedSubstraction");
                  QTest::addColumn<int>("expectedMultiplication");

                  QTest::newRow("all zero") << 0 << 0 << 0 << 0 << 0 ;
                  QTest::newRow("same number") << 10 << 10 << 20 << 0 << 100 ;
                  QTest::newRow("different number") << 10 << 5 << 15 << 5 << 50 ;
                  QTest::newRow("1 +ve, 1 -ve number") << 10 << -5 << 5 << 15 << -50 ;
                  QTest::newRow("-ve numbers") << -5 << -10 << -15 << 5 << 50;
                  

                  }

                  void TestCalculator::testNumbers()
                  {
                  QFETCH(int, a);
                  QFETCH(int, b);
                  QFETCH(int, expectedAddition);
                  QFETCH(int, expectedSubstraction);
                  QFETCH(int, expectedMultiplication);

                  Maths objNumber;
                  
                  int addResult=objNumber.add(a,b);
                  qDebug()<< a;
                  qDebug()<< b;
                  qDebug()<< expectedAddition;
                  qDebug()<< addResult;
                  
                  QCOMPARE(addResult, expectedAddition);
                  
                  int diffResult=objNumber.subtract(a,b);
                  qDebug()<< a;
                  qDebug()<< b;
                  qDebug()<< expectedSubstraction;
                  qDebug()<< diffResult;
                  QCOMPARE(diffResult, expectedSubstraction);
                  
                  int mulResult=objNumber.multiplication(a,b);
                  qDebug()<< a;
                  qDebug()<< b;
                  qDebug()<< expectedMultiplication;
                  qDebug()<< mulResult;
                  QCOMPARE(mulResult, expectedMultiplication);
                  

                  }

                  QTEST_APPLESS_MAIN(TestCalculator)

                  #include "tst_testcalculator.moc"

                  ********* Start testing of TestCalculator *********
                  Config: Using QtTest library 5.12.7, Qt 5.12.7 (x86_64-little_endian-llp64 shared (dynamic) debug build; by GCC 7.3.0)
                  PASS : TestCalculator::initTestCase()
                  PASS : TestCalculator::test_case1()
                  QFATAL : TestCalculator::testNumbers() ASSERT failure in QTest::fetchData(): "Test data requested, but no testdata available.", file qtestcase.cpp, line 1167
                  FAIL! : TestCalculator::testNumbers() Received a fatal error.
                  Unknown file(0) : failure location
                  Totals: 2 passed, 1 failed, 0 skipped, 0 blacklisted, 1ms
                  ********* Finished testing of TestCalculator *********
                  00:05:38: The program has unexpectedly finished.
                  00:05:38: The process was ended forcefully.

                  This is the testcalculator.pro file

                  QT += testlib
                  QT -= gui

                  CONFIG += qt console warn_on depend_includepath testcase
                  CONFIG -= app_bundle

                  TEMPLATE = app

                  SOURCES += tst_testcalculator.cpp
                  Maths.cpp

                  HEADERS +=
                  Maths.hpp

                  Thank you,
                  Surendranath

                  S Offline
                  S Offline
                  Surendranath
                  wrote on 16 Sept 2020, 07:35 last edited by
                  #8

                  @Surendranath Ok i got the solution .
                  And where i went wrong was i gave the wrong test case definition.
                  So i correct it testNumbers_data() instead of test_case1().
                  Now problem solved.
                  Thank you.

                  1 Reply Last reply
                  2

                  • Login

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