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


I have a Java code that works in one (main) thread, from the main thread, I create a new thread I am in a server call in which I call. After making a server call, I am doing something in the new thread and then the code is included in the main thread.

I am using Eclipse Jobs to call the server.

I want to know, how do I write a Junket Test case for this?

You may need to restructure your code so that it can be easily tested.

I can look at several different areas for testing:

  1. Thread management code: code to launch thread (s) and maybe wait for the result
  2. Running in the "worker" code thread
  3. There may be concurrent problems when multiple threads are activated

    The structure of your implementation, so that Your Thread Management Code is an atheist worker. You can then use the mock workers to enable the trial of thread management - for example a fake worker who fails in a certain way, then you have the ability to test some paths in the management code.

    Implement the worker code so that it can be run in isolation.

    For the concurrency, it will help in testing the link given by Abhijit Kasania.

Comments