Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clear instructions on using scalatest with the simple build tool

There's a lot of stuff from Scala 2.8.0-RC, but things seem to have changed a lot since then and I'm not finding much.

I'd just like some clear instructions on how to get my SBT project (SBT version 0.7.4, Scala version 2.8.1) working with scala test.

Thanks so much.

like image 594
Aaron Yodaiken Avatar asked Feb 26 '11 04:02

Aaron Yodaiken


1 Answers

First thing is to add the ScalaTest dependency to your SBT project. In <project_root>/project/<CLASS_THAT_EXTENDS_DEFAULTPROJECTINFO>.scala you will need to add the line:

val scalatest = "org.scalatest" % "scalatest" % "1.3"

This adds the ScalaTest dependency to your project. ScalaTest 1.3 will work fine with Scala 2.8.1.

Then create a test class like so in <project_root>/src/test/scala:

class Foo{
  def addOne(i: Int): Int = {
    i + 1
  }
}


import org.scalatest.Spec

class Test extends Spec {

  describe("Add one test") {

  it("Should be two") {
    expect(2) { new Foo().addOne(1) }
  }    
}

}

First run 'sbt update' so that sbt will update your repo with the new ScalaTest dependency.

With this you should be able to run 'sbt test' or simply 'test' in the SBT console and it will run the test.

like image 156
Brian Avatar answered Oct 17 '22 20:10

Brian