11

I'm learning Scala now. I saw there are 2 test frameworks there, ScalaTest and Specs. My only problem is that I'm not still at ease with the language to decide which is better. Also I'm used to write tests before code, at the moment I have no clear idea how to do it in functional programming. Ideally I'd like to learn Scala in a TDD fashion, is there any resource about it?

Uberto
  • 2,712
  • 3
  • 25
  • 27

3 Answers3

7

There is a functional koan which might be something you are looking for. Dick Wall from the Java Posse started a github project:

https://github.com/relevance/functional-koans/tree/scala

You need maven to start it via mvn package.


There is another Koan:

http://www.scalakoans.org/

Thanks to @MikeHoss!

michael.kebe
  • 10,916
  • 3
  • 44
  • 62
  • @uberto, from what I can gather, 'functional koans' appear to be exercises you can do to learn functional programming, whereby you're given a failing test and you have to make it pass. Is that right, Michael? – Grant Crofton Nov 16 '10 at 14:54
  • Yeah, correct. There is a project setup with a bunch of unit tests. To make progress you have to change the currently failing unit test to make it pass. Then the next test fails and you have to learn something new. The first unit test is trivial: `assert(false) // should be true` – michael.kebe Nov 17 '10 at 06:20
  • really interesting! I'll try! – Uberto Nov 20 '10 at 14:21
2

So, test frameworks. There are other questions about that, though I'd like to point out that there's also ScalaCheck. ScalaCheck is not as fully features as Specs and ScalaTest, but, on the other hand, both Specs and ScalaTest can integrate with it.

Personally, I'd rather go with ScalaCheck, which is likely very different from the unit testing frameworks you are used to. This difference can be good in keeping you from stating tests in an object oriented manner.

Now, to the main concern of your question: is there a TDD-like Scala tutorial? I don't know of any, though the answer about functional koans appear to approach what you want.

Community
  • 1
  • 1
Daniel C. Sobral
  • 295,120
  • 86
  • 501
  • 681
1

ScalaTest is the more richly-featured and flexible of the two frameworks.

Having said that... I'm currently favouring Specs, they seem to be doing a far better job of keeping up with the latest Scala releases and the IntelliJ integration also seems to work better.

Specs also has the advantage, for you, of having a smaller API to learn.

Kevin Wright
  • 49,540
  • 9
  • 105
  • 155
  • Right after 2.8 came out ScalaTest 1.2 was released final, which works just fine with Scala 2.8. Kevin somehow didn't know that ScalaTest 1.2 worked with Scala 2.8. ScalaTest 1.3, which also works with Scala 2.8, is the current release as of March 20, 2011. – Bill Venners Mar 20 '11 at 20:34
  • At the time I wrote this answer, I'd recently been working with a lot of 2.8 release candidates, which specs was tracking very closely. I still recall the frustration in being unable to update a project simply because of a ScalaTest dependency. Since then, ScalaTest started tracking its own dependencies via Maven, so rapid-fire releases should be possible and I don't see this affecting me in the future (handy to know, with 2.9.0 about to make release candidate) – Kevin Wright Mar 21 '11 at 09:14