Hacker News new | ask | show | jobs
by the_af 3749 days ago
Out of curiosity, what's wrong with ScalaTest? I particularly like the WordSpec style, which is easy to write and looks newbie-friendly.

It's true SBT is not suitable for beginners. Regrettably, neither is Maven. I don't know which tool is...

1 comments

I find it makes tests much less comprehensible (and gives them worse IDE integration) than JUnit; it uses gratuitous operator overloading style with e.g. "should". And for a beginner it doesn't really offer any advantage - if you're using generators or the like I can see it might be helpful, but for basic unit testing I find straightforward code with JUnit is much easier.
Using the natural language style assertions is optional though, and only work if you incorporate the 'Matchers' trait in your tests. If that's too magical, you can still use plain old assertions or one of the other styles here http://www.scalatest.org/user_guide/using_assertions
Everything is optional, which is a nightmare for consistency. Using JUnit there's only one style of testing and every test follows it.
You can do what we did in my team: decide on a style of testing and stick to it (in our case, I liked WordSpec). With JUnit you can't do this, because there is only one style.

I particularly liked the "should", "must", "where", etc. DSL. If I remember correctly, this style of testing comes from the Rails community. I guess it's a matter of taste, but I would definitely recommend it to newbies.

I wouldn't recommend it to newbies at all, because it's using relatively advanced Scala features - implicit conversions to make the operators available, "word word word" style desugaring into method calls. Of course these are things that you have to learn eventually and that have value, but making a newbie learn how they work before they can test anything is throwing them in at the deep end, and having to use a test framework that you can't understand isn't good.
A lot of Java programmers don't understand how JUnit works, nor need to, and they still manage to use it, so I don't think this is a strong argument.

The point of DSLs is that they feel natural for their job, regardless of how they are implemented. You can use a DSL without understanding how it works "behind the scenes". To me, ScalaTest with WordSpec seems more natural than JUnit, and at least my own experience shows I'm right: I've successfully introduced it in a team of newbies.