How do I write a JUnit test case to test threads and events

前端 未结 7 848
无人共我
无人共我 2020-12-09 17:07

I have a java code which works in one (main) thread. From the main thread, i spawn a new thread in which I make a server call. After the server call is done, I am doing some

7条回答
  •  离开以前
    2020-12-09 17:41

    The resources provided by Abhijeet Kashnia may help, but I am not sure what you are trying to achieve.

    You can do unit testing with mocks to verify your code, that won't test concurrency but will provide coverage. You can write an integration test to verify that the threads are being created and joined in the fashion you expect.However this will not guarantee against concurrency problems. Most concurrent problems are caused by timing bugs which are not predictable and thus can't be tested for accurately.

提交回复
热议问题