我正在编写一些集成测试,以确保我的客户可以正常工作。我拥有的测试的简化形式是:
class MyTest with FlatSpec {
val service = new MyService()
"MyService" should "Accept a request and publish a notification" {
val request = new Request(id = "1234")
val notification: Future = service.publish(request)
Future.Await(notification)
}
it should "Produce the expected result" {
val request = new Request(id = "5678")
val notification: Future = service.publish(request)
Future.Await(notification)
val result: Seq = service.getResult(id = "5678")
result should not be empty
}
}
请注意,第一次测试中的所有步骤都必须在第二次测试中重复。该服务在套件的整个生命周期中都有效,并且服务组件中发生的事情并非廉价操作。我想知道是否有可能确保测试按顺序运行,以便我可以像这样重构我的测试:
class MyTest with FlatSpec {
val service = new MyService()
val id = "1234"
"MyService" should "Accept a request and publish a notification" {
val request = new Request(id)
val notification: Future = service.publish(request)
Future.Await(notification)
}
it should "Produce the expected result" {
val result: Seq = service.getResult(id)
result should not be empty
}
}