jfinn88
18th May 2017, 22:26
I'm new to TDD and Google Unit Test and having issues setting up some simple testing for class that #include <QObject>.
I have got the testing libraries installed for Qt Creator and have the Auto test plugin enabled
qtdeclarative5-dev-tools qtdeclarative5-test-plugin
I have a SUBDIR project that has two projects in it: one project is for the QML/C++ application and the other sub project is for Auto Unit Testing (Google Test & QtQuick Test)
TEMPLATE = subdirs
SUBDIRS += Application \
AutoTests
I can create a simple class (multiply.cpp) in my qml/c++ app and able to test it in the my other sub-project GTest
Header file for multiply.cpp
#ifndef MULTIPLY_H
#define MULTIPLY_H
class Multiply
{
public:
Multiply();
int TwoNums(int x, int y);
};
#endif // MULTIPLY_H
Here is my Test Function for my multiply class example (I had to add existing files and select my multiply.cpp file and add it to this sub=projects sources)
#include <gtest/gtest.h>
#include <gmock/gmock-matchers.h>
#include "../../Application/Application/multiply.h"
using namespace testing;
TEST(Multiply_Test1, Multiply_Set1)
{
Multiply multiplyObj;
EXPECT_EQ(6, multiplyObj.TwoNums(2,3));
ASSERT_THAT(0, Eq(0));
}
This is my project structure
12477
I don't know if I need to mock the class to take away the dependencies of QObject sub class ? I not sure how to write an appropriate test for something that sub-classes another object
I'm having issue testing any class that use a sub class like QObject, Get errors saying fatal error: QObject: No such file or directory (this happens for each #include)
class ListView : public QObject
{
Q_OBJECT
I'm also trying to get QtQuick Test to work with this project too but not having any luck understanding how to implement it fully
I set up an Auto Test SubDir
I have tried creating a test_Button.qml file with test cases in it
I added Macro for running QtQuick Test to a .cpp file so that the test "harness" can run the tests (test harness scans current directory for tst_ files) unless environment variable is set specifying path
QUICK_TEST_MAIN(example)
I'm not sure with the SUBDIR structure where my Quick Unit test should live
I'm I setting everything up correctly Google test? and QtQuick Test?
What is the best way to implement Auto Unit Testing in Qt using Google Tests ?
any advice or examples would be awesome
I have got the testing libraries installed for Qt Creator and have the Auto test plugin enabled
qtdeclarative5-dev-tools qtdeclarative5-test-plugin
I have a SUBDIR project that has two projects in it: one project is for the QML/C++ application and the other sub project is for Auto Unit Testing (Google Test & QtQuick Test)
TEMPLATE = subdirs
SUBDIRS += Application \
AutoTests
I can create a simple class (multiply.cpp) in my qml/c++ app and able to test it in the my other sub-project GTest
Header file for multiply.cpp
#ifndef MULTIPLY_H
#define MULTIPLY_H
class Multiply
{
public:
Multiply();
int TwoNums(int x, int y);
};
#endif // MULTIPLY_H
Here is my Test Function for my multiply class example (I had to add existing files and select my multiply.cpp file and add it to this sub=projects sources)
#include <gtest/gtest.h>
#include <gmock/gmock-matchers.h>
#include "../../Application/Application/multiply.h"
using namespace testing;
TEST(Multiply_Test1, Multiply_Set1)
{
Multiply multiplyObj;
EXPECT_EQ(6, multiplyObj.TwoNums(2,3));
ASSERT_THAT(0, Eq(0));
}
This is my project structure
12477
I don't know if I need to mock the class to take away the dependencies of QObject sub class ? I not sure how to write an appropriate test for something that sub-classes another object
I'm having issue testing any class that use a sub class like QObject, Get errors saying fatal error: QObject: No such file or directory (this happens for each #include)
class ListView : public QObject
{
Q_OBJECT
I'm also trying to get QtQuick Test to work with this project too but not having any luck understanding how to implement it fully
I set up an Auto Test SubDir
I have tried creating a test_Button.qml file with test cases in it
I added Macro for running QtQuick Test to a .cpp file so that the test "harness" can run the tests (test harness scans current directory for tst_ files) unless environment variable is set specifying path
QUICK_TEST_MAIN(example)
I'm not sure with the SUBDIR structure where my Quick Unit test should live
I'm I setting everything up correctly Google test? and QtQuick Test?
What is the best way to implement Auto Unit Testing in Qt using Google Tests ?
any advice or examples would be awesome