SBT + ScalaTest from WoW addict perspective

Reading SBT Tutorial is a bit painful if your Scala-fu is not very strong. You may feel a bit like a leveling player travelling trough SV in WoW:

But SBT is easy. Check out following short info and judge by yourself:

Hello World in SBT

Simple program printing some stuff, that can be handeld by SBT (sample project)
We have config file: build.sbt

lazy val root = (project in file(".")).
		name := "hello",
		version := "1.0",
		scalaVersion := "2.11.7"

add some Scala code inside root dir or src/main/scala:

object Hi {
	def main(args: Array[String]) = println("Hi!")

We can compile this by:

sbt compile

or play around with more commands (sbt run, sbt package, sbt help) or even more SBT commands.

Super easy stuff.

SBT project with ScalaTest

To do some testing we need to (sample project):
1) add dependency for ScalaTest in build.sbt:

lazy val second = (project in file(".")).
		name := "second",
		version := "1.0",
		scalaVersion := "2.11.7",
		libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test"

2) add some tests in src/test/scala:

import org.scalatest.FlatSpec

class SetSpec extends FlatSpec {

  "An empty Set" should "have size 0" in {
    assert(Set.empty.size == 0)


and run tests: sbt test or even better ask SBT to compile and run tests whenever something is changed:

sbt ~ test

Easy and straight forward.

Some more stuff about SBT and ScalaTest:

This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s