Results 1 to 9 of 9

Thread: How can we make unit test for multithread in QT

  1. #1
    Join Date
    Sep 2008
    Posts
    93
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default How can we make unit test for multithread in QT

    I hope to make unit test for the multithread library. But I do not know how to test multi thread with QT?

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

    Default Re: How can we make unit test for multithread in QT

    You want the test to be multithreaded or the unit under test is multithreaded? If the former, create two separate test classes and run them concurrently. If the latter, test the library as usual, you needn't change anything in your test code.

  3. #3
    Join Date
    Sep 2008
    Posts
    93
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: How can we make unit test for multithread in QT

    the unit under test is multithreaded.

    how can we make unit test to test the thread?

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

    Default Re: How can we make unit test for multithread in QT

    What exactly do you want to test?

  5. #5
    Join Date
    Sep 2008
    Posts
    93
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: How can we make unit test for multithread in QT

    I just hope to test:
    The two threads are running concurrently.
    The second thread is running background, and it does something

    How can we test?

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

    Default Re: How can we make unit test for multithread in QT

    If you keep giving such general answers to my questions, your problem will remain unsolved. I'm asking what exactly do you want to test - what the exact functionality of the unit under test is.

  7. #7
    Join Date
    Oct 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How can we make unit test for multithread in QT

    Hi, I'm running into the similar problem, and found your discussion.
    My problem is:
    main thread creates worker thread A, A is doing network communication work. main thread emit a signal to thread A's one slot. Then thread A starts sending socket. When A receives socket, it emits signal back to main thread's function slot. So main threads needs qapplication's event dispatcher.

    Now I tried gtest and Qt test, both of them do not have event dispatcher. Their main thread will keep running all tests and exit. How can I unit test my main thread slot.

    Thanks,

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

    Default Re: How can we make unit test for multithread in QT

    Each test should enter the event loop (by calling QCoreApplication::exec()) as part of the test and when the test is complete it should quit the event loop and report the result. Then next test will start, will enter the event loop and so on.
    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.


  9. #9
    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: How can we make unit test for multithread in QT

    Or using a test-local QEventLoop instance that quits on the result signal.
    Or using QTest::qWait()

    Cheers,
    _

Similar Threads

  1. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 05:57
  2. How to unit test a Qt Gui
    By mitskits in forum Qt Programming
    Replies: 1
    Last Post: 20th January 2006, 07:36

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.