A few weeks ago I decided to learn Scala in order to develop the website for my latest side project. This led me down the road of trying to learn Google App Engine/Java, Lift, Maven, Git, ScalaTest, Spec and much more, so it’s been pretty slow going. Especially due to diversions into Cassandra, MongoDB, Tokyo Cabinet, Hadoop and HBase.
I’m a huge fan of JUnit for unit testing Java code, so I was happy when Bil Venners announced the release of ScalaTest 1.0 at a BASE meeting at Twitter. I really like being able to quickly run tests in Eclipse, but it wasn’t obvious to me how to do this with ScalaTest, especially when using the BDD styles of testing, like Spec. Creating test runners manually for each class was a deal killer. I finally found some info that mostly clarified things.
A simple example is helpful, so here you go:
import org.scalatest.Spec
import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith
@RunWith(classOf[JUnitRunner])
class MinimalSpec extends Spec {
describe("My class") {
it("should have testable behavior like...") {
assert(true)
}
}
}
After creating the class, do one of the following:
- Right click on file in tree and select Run As -> JUnit Test
- Select file in tree and press
Alt-Command-X + T
on OS X orAlt-Shift-X + T
on other OSs
After the test completes, the JUnit view should display something like:
We have some small sections on Scala in the Maven Handbook. We’re planning on expanding these in the near future. Let me know via book@sonatype.com if you want us to focus on anything in particular.
Thanks, Tim! I’ve been very pleased with Maven. Also, Sonatype’s m2eclipse plug-in has been extremely helpful so far and was very easy to sort out, at least for everything I’ve needed to get started on building a Scala Lift app. I’ll definitely check out the Maven Handbook.