Unable to create C++ google test for the C++ class
-
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_controllerPlease do help .Thanks
-
The error tells you what to do - create a QApplication object before you create your widgets.
-
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)
{
} -
@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.
-
#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 -
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.