Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Object A {
  def a = { something}
}

// I've import A, but still have error message:  not found: type A
val x = mock[A]
like image 968
user398384 Avatar asked Feb 25 '23 11:02

user398384


1 Answers

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.

like image 121
Daniel C. Sobral Avatar answered Feb 27 '23 00:02

Daniel C. Sobral