What are some strategies to unit test a scheduler?

后端 未结 5 1730
温柔的废话
温柔的废话 2020-12-15 23:05

This post started out as \"What are some common patterns in unit testing multi-threaded code ?\", but I found some other discussions on SO that generally agreed that \"It is

5条回答
  •  青春惊慌失措
    2020-12-15 23:43

    If the scheduler delegates to an Executor or ExecutorService to run the tasks, you could use Dependency Injection to remove a direct dependency on the type of Executor, and use a simple single threaded Executor to test much of the functionality of your scheduler without the complication of truly multi-threaded code. Once you'd got those tests debugged, you could move on the the harder, but now substantially reduced in magnitude, task of testing thread-safety.

提交回复
热议问题