I hope to make unit test for the multithread library. But I do not know how to test multi thread with QT?
I hope to make unit test for the multithread library. But I do not know how to test multi thread with 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.
the unit under test is multithreaded.
how can we make unit test to test the thread?
What exactly do you want to test?
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?
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.
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,
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.
Or using a test-local QEventLoop instance that quits on the result signal.
Or using QTest::qWait()
Cheers,
_
Bookmarks