Results 1 to 4 of 4

Thread: How do you run multiple test classes?

  1. #1

    Question How do you run multiple test classes?

    I previously asked this in the "newbie" forum but got no responses, perhaps it's not a "newbie" question ;-)...

    I've got a directory structure like this:
    Qt Code:
    1. /proj
    2. proj.pro
    3. main.cpp
    4. /tests
    5. projtests.pro
    6. main.cpp
    7. /data
    8. data.pri
    9. dataclass.h
    10. dataclass.cpp
    11. /tests
    12. datatests.pri
    13. dataclasstests.h
    14. dataclasstests.cpp
    To copy to clipboard, switch view to plain text mode 

    Every dir has a /tests dir beneath it with tests, and main.pro includes data.pri whereas maintests.pro includes datatests.pri.

    The only thing is, I can't figure out how to run tests when set up like this?
    The tutorial says you have to do this in your test class:
    Qt Code:
    1. QTEST_MAIN(<test class name>)
    2. #include "<test class name>.moc"
    To copy to clipboard, switch view to plain text mode 

    But as far as I can tell, QTEST_MAIN creates a main function that tests that one class. I'm going to have multiple classes to test, and I want the test main function to live in /proj/tests/main.cpp.

    Also the #include "<name>.moc" always shows a warning in QtCreator that the file doesn't exist, although there is no compile-time error.

    How do you do this?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How do you run multiple test classes?

    Posting the same question twice won't help. I have seen your previous post but to be honest I don't know what you wanted to achieve Usually if you want to have multiple tests, you do that through multiple executables or you don't use QTEST_MAIN but provide your own main() where you call QTest::exec() to trigger testing using a given class.

    I don't know if it answers your question but in case it does, here you are.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3

    Default Re: How do you run multiple test classes?

    Well, maybe it doesn't matter, since the same person always answers posts .

    To elaborate on what I'm getting at, I'm used to frameworks(junit, nunit) / IDEs(eclipse, VS) that will run "all" your tests (for a given project) in one go, even if they are in different libraries. I'm trying to do that with QT.

    So you're saying I need /proj/tests/projtests.pro to look something like this:
    Qt Code:
    1. QT += testlib
    2. TARGET = Tests
    3. CONFIG += console
    4. TEMPLATE = app
    5. SOURCES += main.cpp
    6.  
    7. include(../data/tests/datatests.pri)
    8. include(../foo/tests/footests.pri)
    9. include(../bar/tests/bartests.pri)
    To copy to clipboard, switch view to plain text mode 

    And then a corresponding /proj/tests/main.cpp like this:
    Qt Code:
    1. #include <QTest>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. DataTests test1;
    6. FooTests test2;
    7. BarTests test3;
    8.  
    9. QTest.qExec(&test1);
    10. QTest.qExec(&test2);
    11. QTest.qExec(&test3);
    12.  
    13. return 0;
    14. }
    To copy to clipboard, switch view to plain text mode 

    Do I need to #include the .moc files in this case?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How do you run multiple test classes?

    qmake won't "run" anything for you. I'm using a simple script to do that.
    bash Code:
    1. #!/bin/sh
    2.  
    3. for i in 1 2 3 model
    4. do
    5. cd test$i
    6. ./test$i
    7. cd ..
    8. done
    To copy to clipboard, switch view to plain text mode 

    test1, test2, test3 and testmodel are my tests.

    You need to include "main.moc" only if there is a Q_OBJECT macro in the main.cpp file.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Multiple Classes setText Update
    By Msnforum in forum Qt Programming
    Replies: 5
    Last Post: 30th January 2009, 16:40
  2. Professional Classes & Objects Structure
    By webstylemedia in forum Newbie
    Replies: 4
    Last Post: 4th August 2008, 11:50
  3. GUI version of test runner
    By Intaek Lim in forum Qt Programming
    Replies: 1
    Last Post: 17th April 2007, 11:21
  4. Object and multiple inheritance for interfaces
    By brcain in forum Qt Programming
    Replies: 6
    Last Post: 16th November 2006, 20:05
  5. How to unit test a Qt Gui
    By mitskits in forum Qt Programming
    Replies: 1
    Last Post: 20th January 2006, 08:36

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.