Results 1 to 2 of 2

Thread: Issues on Qt test framework

  1. #1
    Join Date
    Feb 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Issues on Qt test framework

    Hello everyone !

    I'm a in a professionnal licence (France) and i have issue on my tutored project.
    I have a big problem on the Qt test framework and online tutorials I find didn't help me at all ... All take for exemple the ToUpper() method test, but the issue is because i didn't find how to use this freaking tests on my own classes ! T-T
    I've some questions on QT Test:
    -> do I made a .cpp and a .h for my test class ? Or putting all on the .cpp ?
    -> I my class need to be in antoher project ? Or in the same project ? If i need to make another project, how to link both ?
    -> do i need to importe .cpp of the class i need to test or the .h ? Or both maybe ?

    This i the code of my test class:

    Qt Code:
    1. #include <QString>
    2. #include <QtTest>
    3. #include "carre.h"
    4. #include "cercle.h"
    5. #include "point.h"
    6. #include "rectangle.h"
    7. #include "segment.h"
    8. #include "figure.h"
    9. #include "position.h"
    10.  
    11. class TestsProjetTest : public QObject
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. TestsProjetTest();
    17. Carre* c;
    18. Position* p;
    19.  
    20. private Q_SLOTS:
    21. void testDeplacement();
    22. };
    23.  
    24. TestsProjetTest::TestsProjetTest()
    25. {
    26. c = new Carre();
    27. p = new Position(10, 10);
    28. }
    29.  
    30. void TestsProjetTest::testDeplacement()
    31. {
    32. QVERIFY2(true, "Failure");
    33. }
    34.  
    35. QTEST_APPLESS_MAIN(TestsProjetTest)
    36.  
    37. #include "tst_testsprojettest.moc"
    To copy to clipboard, switch view to plain text mode 
    It's really a simple code which actually don't test anything, but i've some issues i didn't understand what can I do... There are the issues:
    Qt Code:
    1. error: undefined reference to `Carre::Carre()'
    2. error: undefined reference to `Position::Position(int, int)'
    3. :-1: error: collect2: error: ld returned 1 exit status
    To copy to clipboard, switch view to plain text mode 

    It's really strange because methods work pretty well in my project and don't have any problems... I put NameOfMyClass:: for each method on my project, and it work ! So i don't understand why i have problems like that ...

    I have there problems for one week and i didn't find a solution ... I really need help

    And please, dont redirect me on the ToUpper() tuto you find on Qt doc because i didn't help me at all !
    Same thing for the tuto on developpez.net

    I hope you will find the problem and explain to me how to use Qt test framework ! I really need to improve my skill on it, because Qt will be my professionnal IDE, so i need to learn many things !

    Thanks by advance !

    Axel.

  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: Issues on Qt test framework

    Quote Originally Posted by Noren View Post
    -> do I made a .cpp and a .h for my test class ? Or putting all on the .cpp ?
    Both work, for simple tests just a .cpp is usually less work.
    In case of just having a .cpp you need to include the "moc" file at the end of the file (see your current example).

    Quote Originally Posted by Noren View Post
    -> I my class need to be in antoher project ? Or in the same project ? If i need to make another project, how to link both ?
    You can either build the unit (the class you test) as part of the test (add its .cpp to SOURCES and its .h to HEADERS) or you put them in a library that both your application and your tests uses in their respective .pro file's LIBS variable.

    Quote Originally Posted by Noren View Post
    -> do i need to importe .cpp of the class i need to test or the .h ? Or both maybe ?
    including the .cpp is also possible, but very uncommon.

    Quote Originally Posted by Noren View Post
    It's really a simple code which actually don't test anything, but i've some issues i didn't understand what can I do... There are the issues:
    Qt Code:
    1. error: undefined reference to `Carre::Carre()'
    2. error: undefined reference to `Position::Position(int, int)'
    3. :-1: error: collect2: error: ld returned 1 exit status
    To copy to clipboard, switch view to plain text mode 
    Linker error, saying that it can't find the code backing these functions.
    See your second question.

    Quote Originally Posted by Noren View Post
    It's really strange because methods work pretty well in my project and don't have any problems... I put NameOfMyClass:: for each method on my project, and it work ! So i don't understand why i have problems like that ...
    Your main project most likely builds the class as part of its SOURCES or you have it in a library that the main project's LIBS points to.

    Cheers,
    _

Similar Threads

  1. Unit Test: Test if QPushButton has a menu
    By FelixB in forum Qt Programming
    Replies: 1
    Last Post: 7th November 2012, 12:12
  2. Replies: 3
    Last Post: 19th July 2010, 10:59
  3. Issues with the Graphics View Framework
    By lni in forum Qt Programming
    Replies: 8
    Last Post: 26th April 2009, 14:13
  4. A.I. test. A.I. test.
    By Kumosan in forum General Discussion
    Replies: 3
    Last Post: 19th October 2007, 19:19

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.