Is it possible to freeze System.currentTimeMillis() for testing

前端 未结 6 2533
孤街浪徒
孤街浪徒 2021-02-20 02:24

For some testing purposes I would like to predict exactly what System.currentTimeMillis() will return. Is there any way in which I can freeze or manually set what w

6条回答
  •  臣服心动
    2021-02-20 02:54

    Is it possible to freeze System.currentTimeMillis()? NO

    You need to use a sort of wrapper around that time value if you want your code to be able to be tested

提交回复
热议问题