Testing with Thread.sleep

后端 未结 6 1841
囚心锁ツ
囚心锁ツ 2021-01-11 16:28

What are the recommended approaches to using Thread.sleep() to speed up tests.

I am testing a network library with a retry functionality when connection

6条回答
  •  长情又很酷
    2021-01-11 16:46

    It is usually a good idea to delegate time-related functionality to a separate component. That include getting the current time, as well as delays like Thread.sleep(). This way it is easy to substitute this component with mock during testing, as well as switch to a different implementation.

提交回复
热议问题