简体   繁体   中英

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?

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.

Always happy to look at feature requests on ScalaMock if you think something material is missing. One benefit of ScalaMock is probably the leaner syntax, especially when mocking scala.Function* types.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM