Results 1 to 2 of 2

Thread: using google test with Qt qml App

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2016
    Posts
    99
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default using google test with Qt qml App

    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)

    Qt Code:
    1. TEMPLATE = subdirs
    2. SUBDIRS += Application \
    3. AutoTests
    To copy to clipboard, switch view to plain text mode 

    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
    Qt Code:
    1. #ifndef MULTIPLY_H
    2. #define MULTIPLY_H
    3.  
    4.  
    5. class Multiply
    6. {
    7. public:
    8. Multiply();
    9. int TwoNums(int x, int y);
    10. };
    11.  
    12. #endif // MULTIPLY_H
    To copy to clipboard, switch view to plain text mode 

    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)
    Qt Code:
    1. #include <gtest/gtest.h>
    2. #include <gmock/gmock-matchers.h>
    3. #include "../../Application/Application/multiply.h"
    4.  
    5. using namespace testing;
    6.  
    7. TEST(Multiply_Test1, Multiply_Set1)
    8. {
    9. Multiply multiplyObj;
    10. EXPECT_EQ(6, multiplyObj.TwoNums(2,3));
    11. ASSERT_THAT(0, Eq(0));
    12. }
    To copy to clipboard, switch view to plain text mode 

    This is my project structure
    fileStructure_Tamesa.jpg

    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)

    Qt Code:
    1. class ListView : public QObject
    2. {
    3. Q_OBJECT
    To copy to clipboard, switch view to plain text mode 

    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

    Qt Code:
    1. QUICK_TEST_MAIN(example)
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by jfinn88; 19th May 2017 at 00:58.

Similar Threads

  1. How to add google map
    By namitha in forum Newbie
    Replies: 1
    Last Post: 17th February 2017, 09:57
  2. Replies: 1
    Last Post: 9th October 2015, 07:45
  3. QTestLib vs Google Test
    By tonka3000 in forum Qt Programming
    Replies: 1
    Last Post: 19th July 2013, 15:55
  4. Unit Test: Test if QPushButton has a menu
    By FelixB in forum Qt Programming
    Replies: 1
    Last Post: 7th November 2012, 12:12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.