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. Unit Testing with GTest
Qt 6.11 is out! See what's new in the release blog

Unit Testing with GTest

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 814 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.
  • F Offline
    F Offline
    Fleshbits
    wrote on last edited by Fleshbits
    #1

    The company I am writing code for uses GTest in their CI/CD. I'd really rather not bring in QTest if at all possible.

    However, GTest requires you to run their test runner on the main thread:

    int main(int argc, char* argv[])

    {
        ::testing::InitGoogleTest(&argc, argv);
        return RUN_ALL_TESTS();
    }
    

    So does Qt Application, which seems necessary for everything in Qt, even the websocket code I want to test.

    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        // SNIP
        
        EchoServer *server = new EchoServer(port, debug);
        QObject::connect(server, &EchoServer::closed, &a, &QCoreApplication::quit);
    
        return a.exec();
    }
    

    So, how would I go about testing the class I made based on the echo sever example
    https://code.qt.io/cgit/qt/qtwebsockets.git/tree/examples/websockets/echoserver?h=5.14

    in Gtest?

    I've even tried using the wizard in Creator according to the instructions at:
    https://doc.qt.io/qtcreator/creator-autotest.html
    and the code it generates also does not start a QApplication, so anything that needs QApplication running cannot be tested, unless I am missing something.

    1 Reply Last reply
    0

    • Login

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