Search code examples
scalaplayframeworkmockitoplayframework-2.5scalamock

Mocking classes in Play for Scala


I'm planning on using ScalaTest to test Play Controllers, but still undecided if I should mock with Mockito or ScalaMock. The Play website mentions Mockito, however it seems to focus on Java. ScalaMock looks more natural when developing applications in Scala, however from what I read it seems to support fewer test scenarios compared to Mockito, and it's also less mature. Any suggestions?


Solution

  • The Play website mentions Mockito, however it seems to focus on Java.

    Mockito was written for Java but that does not stop it being a very effective tool in Scala projects and is used pretty extensively in the Scala community I believe.

    I have used both but tend to use Mockito when I have a choice since I tend to prefer the syntax a little more - but this is more personal preference. Mockito has been around a lot longer than ScalaMock and is much more actively maintained because of it's much larger contributor base.

    Have a play around with both first off, or else if you are unsure I would personally just go with Mockito.

    I do try and check my design frequently in order to check that I really need those mocks however - it's good practice as I'm sure you are aware.