Testing dilemma : ScalaTest vs Specs2, ScalaMock vs Mockito?

4,877 views
Skip to first unread message

Nathan W

unread,
Feb 21, 2014, 4:26:14 PM2/21/14
to scala...@googlegroups.com
Guys,

Newbie here and I 've just started using Scala very recently and our team is in a dilemma between picking testing frameworks. Would love to hear from you guys especially those of you who have been using these frameworks for a while:

ScalaTest vs Specs2?

I prefer the syntax for ScalaTest better and it seem like ScalaTest has better documentation that is easier to follow. Specs2 seem very interesting and seem to have some advanced features (which I don't fully comprehend) and Play ships with specs by default.
However, I keep hearing that Specs2 tests can be very slow to compile. Is it worth using Specs2?


ScalaMock vs Mockito?

I am switching from .NET background so I don't have any preference. ScalaMock appeals to me because it's the only Mock framework written in Scala that support Scala features like Polymorphic, type constrains and etc..  Mockito seem to have a strong followers in Java community. What are the risks of using ScalaMock (in addition to relying on one developer..)? What will I be missing if I choose Mockito?


Thanks!

Paul Keeble

unread,
Feb 21, 2014, 4:55:19 PM2/21/14
to Nathan W, scala-user
I have previously been using ScalaTest and got to know it reasonably well. With a recent Play app I have been using specs2 and more or less it does the same thing. The main difference really is that the specs2 tests make fixtures a little more convoluted but also a little easier but the assertions have to be limited to one. Specs has less options for how the tests are written as it only supports two styles, whereas Scalatest supports many many different types, but you probably wont want to be using them all in a project anyway.

I haven't so far noticed that they are slow to compile, they seem reasonably quick to run and they run in parallel within a Spec so that speeds things up quite a bit. I perhaps haven't spent enough time other than to say I don't really care one way or the other, I am happy enough with both. Forced to choose I would choose ScalaTest, I prefer the syntax options for the Specs and its better documented but Specs2 is by no means poorly documented its just the reference docs are a little lacking.

PK

etorreborre

unread,
Feb 23, 2014, 5:52:43 PM2/23/14
to scala...@googlegroups.com, Nathan W
Hi Paul,

You write "a little easier but the assertions have to be limited to one". This shouldn't be the case, there are traits to change this behavior if this is the case. Can you show some code where this happens?

Thanks,

Eric.

Bruno Bieth

unread,
Feb 24, 2014, 8:48:19 AM2/24/14
to scala...@googlegroups.com
There's maybe a third alternative, if you're looking for a simple and well-known testing framework together with typesafe extensible and simple matchers: JUnit + Matchete (I'm the author).
With Maven or SBT JUnit gets parallel execution at the class level.

As for mocking, if you design your application carefully you can avoid using a framework at all, writing your own mocks manually when needed.
I would suggest to begin with this approach as it forces you to reconsider your design when the need for a mocking framework becomes too strong - I've seen awful designs alleviated by extensive mocking.
But don't get me wrong, I'm not saying mocking is bad per-se, just that it's not necessarily a must have when you start a new project. If you haven't read it yet here is a good post on the topic.

Bruno

PS: as a side note, SBT might get better testing in 0.14 if https://github.com/sbt/sbt/pull/1119 gets merged ;)
Reply all
Reply to author
Forward
0 new messages