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



  • 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.


  • Lifetime Qt Champion

    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.



  • 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 ?


  • Lifetime Qt Champion

    QT += widgets testlib
    
    SOURCES = testqstring.cpp
    

    And I've changed the last line for

    #include "testqstring.moc"
    


  • @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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.