我开始在sbt上使用ScalaTest.该build.sbt如下:
name := "MySpecSample"
version := "1.0"
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.0" % "test"
scalaVersion := "2.10.3"
Run Code Online (Sandbox Code Playgroud)
初始测试代码在这里.此测试代码单独运行,没有主要组件代码.
import collection.mutable.Stack
import 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 …Run Code Online (Sandbox Code Playgroud)