我想了解如何在ScalaTest中使用fixture setup和teardown。我一直在尝试的一个例子如下:ScalaTest:BeforeAndAfter未运行
import org.scalatest._
import scala.collection.mutable
class SampleTest extends FlatSpec with BeforeAndAfter with Matchers{
before {
// Setup code
}
after {
// Teardown code
}
"A Stack" should "pop values in last-in-first-out order" in {
val stack = new mutable.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 mutable.Stack[Int]
a [NoSuchElementException] should be thrownBy {
emptyStack.pop()
}
}
}
这样做的麻烦在于根本没有执行前或后的块。我觉得我完全按照项目文档中的说明 - 我做错了什么?
你可以添加ScalaTest导入代码以上?我认为它应该工作。 – colinjwebb 2014-09-11 06:37:46
@colinjwebb,是,他们已被添加 – csvan 2014-09-11 09:12:04