PDA

View Full Version : How can we make unit test for multithread in QT



learning_qt
19th December 2008, 06:58
I hope to make unit test for the multithread library. But I do not know how to test multi thread with QT?

wysota
19th December 2008, 08:19
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.

learning_qt
19th December 2008, 10:17
the unit under test is multithreaded.

how can we make unit test to test the thread?

wysota
20th December 2008, 00:18
What exactly do you want to test?

learning_qt
23rd December 2008, 07:56
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?

wysota
23rd December 2008, 08:43
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.

justDance
15th January 2013, 00:09
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,

wysota
15th January 2013, 08:36
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.

anda_skoa
15th January 2013, 16:09
Or using a test-local QEventLoop instance that quits on the result signal.
Or using QTest::qWait()

Cheers,
_