Results 1 to 7 of 7

Thread: Take QtTestLib into use in a Qt project

  1. #1
    Join Date
    Jun 2012
    Posts
    63
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Take QtTestLib into use in a Qt project

    What is the best and easiest way to integrate unit test library, QtTestLib, into existing Qt project with about 50 classes?

    - Can I create for example 'test' folder under main project and put all test classes there including test application project file? How about including classes from existing project
    - Do I have to copy from existing qt project file all the INCLUDES, LIBS, various CONFIGS into test application project file ?

    Are there any example (large) projects where it is used?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Take QtTestLib into use in a Qt project

    Creating a test subdirectory is a very common approach.
    Basicalyl rename your current main .pro file create a new one using template subdirs and putting the previous file as well as tests (name of the test subdirectory) into its SUBDIRS variable,

    Or you restructure the project to have two (or more) subdirectories, one building the application.

    For compiling, one option is to compile all needed classes into the test by adding them to the test's .pro file.
    One other, usually more convenient, option is to put all classes into a static library and linking the main application and each test application against it.

    If you need to share settings between the main application build and the test builds, put those into a .pri file (same syntax as .pro, basically a .pro include) and include it in each .pro file.

    Cheers,
    _

  3. #3
    Join Date
    Jun 2012
    Posts
    63
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Take QtTestLib into use in a Qt project

    Quote Originally Posted by anda_skoa View Post
    Creating a test subdirectory is a very common approach.
    Basicalyl rename your current main .pro file create a new one using template subdirs and putting the previous file as well as tests (name of the test subdirectory) into its SUBDIRS variable,
    Ok, this is the part I do not fully understand. I created new Qt Unit Test project with Qt Creator under 'test' directory.


    QT += testlib

    TARGET = tst_unittitestitest
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    INCLUDEPATH += ../


    SOURCES += tst_unittitestitest.cpp
    DEFINES += SRCDIR=../


    Should I add all the LIBS and INCLUDEPATH's from main application to this test.pro file. Is there easier way just to include all that is in main .pro file ?
    It is very tedious to maintain two .pro files and have basically two copys of INCLUDEPATH's in two .pro files.

    I know Qt is smarter than I think. So please help
    Last edited by phenoboy; 21st March 2013 at 09:11.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Take QtTestLib into use in a Qt project

    Assuming ../ in your INCLUDEPATH refers to the top level directory of your project, then you can create a file like this (e.g. common.pri) in the top level directory

    Qt Code:
    1. INCLUDEPATH += $$dirname(_FILE_)
    2. LIBS #whatever you need
    To copy to clipboard, switch view to plain text mode 

    The all .pro files can simple include it. For example in your test

    Qt Code:
    1. include(../common.pri)
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  5. #5
    Join Date
    Jun 2012
    Posts
    63
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Take QtTestLib into use in a Qt project

    Really having a problem here...

    I'm still having a problem setting up a project with qttestlib. I get unresolved external symbols:

    Qt Code:
    1. myclass.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall MyClass::metaObject(void)const " (?metaObject@MyClass@@UBEPBUQMetaObject@@XZ)
    2.  
    3. myclass.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall MyClass::qt_metacast(char const *)" (?qt_metacast@MyClass@@UAEPAXPBD@Z)
    4.  
    5. myclass.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall MyClass::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@MyClass@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
    6. debug\tst_testtest.exe : fatal error LNK1120: 3 unresolved externals
    To copy to clipboard, switch view to plain text mode 

    Here's my current project zipped.

    http://phenoboy.kapsi.fi/App.zip


    Thanks!
    Last edited by phenoboy; 13th September 2013 at 10:34.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Take QtTestLib into use in a Qt project

    your tests.pro is missing the HEADERS line for the MyClass header

    Cheers,
    _

  7. The following user says thank you to anda_skoa for this useful post:

    phenoboy (13th September 2013)

  8. #7
    Join Date
    Jun 2012
    Posts
    63
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Take QtTestLib into use in a Qt project

    Quote Originally Posted by anda_skoa View Post
    your tests.pro is missing the HEADERS line for the MyClass header

    Cheers,
    _
    yes, it works thanks. Now I have to move SOURCES and HEADERS to own .pri file because I don't like to copy stuff to two places each time I add a new class in main project.

Similar Threads

  1. Replies: 4
    Last Post: 20th January 2013, 11:01
  2. haw to ues project ( skin ) with anther project
    By Master Loda in forum Qt Programming
    Replies: 4
    Last Post: 22nd July 2011, 08:58
  3. Qt project management - bigger project
    By Peppy in forum Qt Programming
    Replies: 11
    Last Post: 24th December 2010, 13:50
  4. Replies: 1
    Last Post: 3rd December 2009, 23:34
  5. Cruise Control and QtTestLib?
    By gfunk in forum Qt Programming
    Replies: 1
    Last Post: 15th November 2007, 19:16

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.