Scalamock reject my mocking attempt by saying that it doesnt support yet more than 22 methods.
The reason is because there are more than 22 methods, all together, in the class I am trying to mock (2 are mine, 20+ are mixed in (from Akka Json Support)).
Any ways to get round this limitation that doesnt involve rethinking the mixing part ?
I used it this way, with scalatest 3.0.2 :
override val apiClient: ApiClient = mock[ApiClient]
(apiClient.getById _).when(15538).returns("data")
Thank you !
I assume you don't actually want to test those JSON and other mixin functions, so I would suggest creating an abstract trait that defines your new, testable signatures and mixing it into your new class. This way you wouldn't need to change your design, and your clients of this ApiClient
class could even decouple fully by using the trait type.
trait MyFunctionality {
def foo(): Unit
def somethingElse(i: Int): Int
}
class ApiClient extends Baseclass with Stuff with MoreStuff with MyFunctionality {
// ...
}
then
val m = mock[MyFunctionality]
(m.foo _).expects().once()
// etc
That way you additionally guard against any code being run in your class (or baseclass) constructors during unit test time. Hope that helps.