Important: Please read the Qt Code of Conduct -

Unit Testing with GTest

  • 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

    in Gtest?

    I've even tried using the wizard in Creator according to the instructions at:
    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.

Log in to reply