How do I mock static function (Object function, not class function) in scala

狂风中的少年 提交于 2019-12-04 11:03:53

You may find this email thread instructive.

Whilst pure mocking of the object is not possible with any tool yet, the thread above does have a few options for you. All of which involve changing your design to some degree.

You don't. Not only A is not a type or class -- it is an instance -- but it is an instance of a singleton (A.type).

What you do instead is put your methods on a trait, and make the object extend it. Then, you mock the trait instead of mocking the object.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!