A comparison of ScalaTest and Spock
Asked Answered
P

2

15

How do scalatest and spock differ? what is the added-value of each ? Which is more agile for Behavior Driven Development (BDD)? Please could you share some thoughts on the matter ?

I want to start BDD, I want to pick one between the two, therefore I'd like to make an educated decision. Hence i get the maximum of information first, especially given that I'm a java programmer and that scala seem to have a learning curve that is important.

Any advise or ideas or return from experiences would be welcome.

Many thanks

Pluralize answered 19/4, 2013 at 14:53 Comment(0)
T
33

In a nutshell, I would recommend to use ScalaTest for testing Scala code, and Spock for testing Java or Groovy code. (Of course, it's also perfectly possible to test Java code with ScalaTest.) Why not give both tools a shot and stick with the one that you are more comfortable with?

Disclaimer: I'm the creator of Spock.

Telstar answered 20/4, 2013 at 3:34 Comment(1)
Peter is being very generous here. Spock's features are without a shadow of a doubt so awesome, that for me, it leaves all testing frameworks in the dust. Having said that, it would be great if @Peter could comment if indeed Spock is workable as the testing framework for Scala...since I read an old post mentioning that Spock's feature are compiler dependent?Kierkegaardian
R
6

While I agree with Peter's answer, I'd like to give my perspective on this.

Both ScalaTest and Spock provide fluent BDD test. However I find that the best feature of Spock is that you can to create single scenario with multiple set of data and expected results. This is very much like Cucumber's Scenario Outline, only run at unit test level.

I can't find other unit test framework/library that does that.

In summary, if you need to test multiple input/output for single test scenario, use Spock, otherwise, feel free to choose whatever you feel comfortable with.

Reconstitute answered 24/12, 2015 at 2:19 Comment(4)
github.com/junit-team/junit4/wiki/parameterized-tests for the same of completeness, jUnit can do the same, it's just uglyLudovika
I don't think so, the parameterized-test will only allow maximum single scenario per unit test class (on constructor parameterized). On field parameterized, you can get more, but only to get uglier.Reconstitute
I agree. It's just that, theoretically, jUnit does have this feature, while the ugliness factor makes it that, practically, it's not anywhere nearly that compelling to use there.Ludovika
Totally agree. However most developers choose will choose the framework that is easy to read. After all tests are living documentation.Reconstitute

© 2022 - 2024 — McMap. All rights reserved.