Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Unable to create C++ google test for the C++ class
QtWS25 Last Chance

Unable to create C++ google test for the C++ class

Scheduled Pinned Locked Moved Unsolved C++ Gurus
6 Posts 2 Posters 506 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.
  • B Offline
    B Offline
    Bharath kumar
    wrote on 13 Nov 2024, 06:35 last edited by
    #1

    Hi Team,

    I got one C++ project. Where I have to write C++ google test unit testing for each file, function's and conditions to improve coverage. But the problem is I am able to write the gtest for non qt functions. If any function is having Qt Widget let's say In my case QTreeView used. I am unable to write the gtest for that class It is giving an error like.

    QWidget: Must construct a QApplication before a QWidget
    WARNING: xml report not find. for: bld_local/TEST_controller

    Please do help .Thanks

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 13 Nov 2024, 06:43 last edited by
      #2

      The error tells you what to do - create a QApplication object before you create your widgets.

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

      1 Reply Last reply
      4
      • B Offline
        B Offline
        Bharath kumar
        wrote on 18 Nov 2024, 07:27 last edited by
        #3

        Yes error tells that create a QApplication before QWidgets. But In my case we have created each test_xxx.cpp file for each source file and we are creating test cases in that. But here I am stuck how and where should I create QApplication object.
        For Ex my class is:

        #include "gtest/gtest.h"
        #include "gmock/gmock.h"

        using::testing::test;
        using::testing::_;

        class ControllFixture: public testing::Test
        {
        };
        TEST_F(ControllFixture, TestValidNode)
        {
        }

        C 1 Reply Last reply 18 Nov 2024, 07:54
        0
        • B Bharath kumar
          18 Nov 2024, 07:27

          Yes error tells that create a QApplication before QWidgets. But In my case we have created each test_xxx.cpp file for each source file and we are creating test cases in that. But here I am stuck how and where should I create QApplication object.
          For Ex my class is:

          #include "gtest/gtest.h"
          #include "gmock/gmock.h"

          using::testing::test;
          using::testing::_;

          class ControllFixture: public testing::Test
          {
          };
          TEST_F(ControllFixture, TestValidNode)
          {
          }

          C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 18 Nov 2024, 07:54 last edited by
          #4

          @Bharath-kumar said in Unable to create C++ google test for the C++ class:

          But here I am stuck how and where should I create QApplication object.

          Before you create any widget.

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

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Bharath kumar
            wrote on 22 Nov 2024, 08:16 last edited by Bharath kumar
            #5
            #include "gtest/gtest.h"
            #include "gmock/gmock.h"
            #include <qt5/QtWidgets/QApplication>
            
            using::testing::test;
            using::testing::_;
            
            class ControllFixture: public testing::Test
            {
            };
            TEST_F(ControllFixture, TestValidNode)
            {
               QApplication app(int argc,char **argv);
               QTreeView* m_treeView = new QTreeView();
               //QListView cm_list_view;
            	//-----------------
            	
            	app.quit();
            }
            

            same problem. Build is successful but test case is failing:
            [ RUN ] ControllFixture.TestValidNode
            QWidget: Must construct a QApplication before a QWidget
            WARNING: xml report not found for: bld_local/TEST_ControllFixture
            Error Summary:
            Program exited with error code: 6
            Run 'man 7 signal' for a description of exit codes

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 22 Nov 2024, 08:42 last edited by
              #6

              See https://doc.qt.io/qt-6/debug.html : set QT_FATAL_WARNING, run your app in the debugger and see where you create a QWidget before a QApplication.

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

              1 Reply Last reply
              0

              1/6

              13 Nov 2024, 06:35

              • Login

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