Sunday, September 17, 2017
Super Simple ScalaTest test
Super Simple ScalaTest test
This the basic tutorial from the ScalaTest homepage. Here we begin by demostrating a very simple ScalaTest test of the Stack class.
First make a file called ./scr/test/scala/ExampleSpec.scala
import collection.mutable.Stackimport org.scalatest._class ExampleSpec extends FlatSpec with Matchers {"A Stack" should "pop values in last-in-first-out order" in {val stack = new Stack[Int]stack.push(1)stack.push(2)stack.pop() should be (2)stack.pop() should be (1)}it should "throw NoSuchElementException if an empty stack is popped" in {val emptyStack = new Stack[Int]a [NoSuchElementException] should be thrownBy {emptyStack.pop()}}}
Second make a file called ./project/build.properties
sbt.version=0.13.12
Third make a file called ./build.sbt
name := "ExampleSpec"version := "1.0"scalaVersion := "2.11.7"libraryDependencies += "org.scalactic" %% download file now