如何在AsyncFeatureSpec中使用贷款固定方法? 我尝试了以下方法:
import akka.actor._
import akka.testkit._
import com.sweetsoft._
import org.scalatest._
import scala.concurrent.duration._
class SapOnlineKafkaOnlineSpec extends fixture.AsyncFeatureSpec with Matchers
with GivenWhenThen
with BeforeAndAfter
with BeforeAndAfterAll {
private val listener1 = TestProbe()
private val detector = system.actorOf(DetectorSupervisor.props)
def withKafkaAndSap(testCode: (ActorRef) => Any) {
}
feature("Detect Kafka and SAP availability") {
info("As a technical user, I want to be notified in real time, if Kafka and SAP is up and running or not.")
scenario("SAP and Kafka are available") in withKafkaAndSap { (listener) =>
Given("I am waiting for the current state message")
detector ! AddNewListener(listener1.ref)
When("I am receive the state message")
val res1 = listener1.expectMsgPF[Assertion](6.second) _
Then("it should contain `SAP and Kafka are online`")
res1 {
case status: ServerStatus =>
status.health should be(ServersOnline)
}
}
}
}
我不知道如何注入贷款方法。
答案 0 :(得分:3)
尝试以下
class SapOnlineKafkaOnlineSpec extends AsyncFeatureSpec with Matchers
with GivenWhenThen
with BeforeAndAfter
with BeforeAndAfterAll {
def withKafkaAndSap(testCode: ActorRef => Future[Assertion]) = {
val actor = ...
testCode(actor)
}
feature("Detect Kafka and SAP availability") {
info("As a technical user, I want to be notified in real time, if Kafka and SAP is up and running or not.")
scenario("SAP and Kafka are available") {
withKafkaAndSap { listner =>
Given("I am waiting for the current state message")
When("I am receive the state message")
Then("it should contain `SAP and Kafka are online`")
succeed
}
}
}
}
请注意贷款固定装置参数类型应为
testCode: ActorRef => Future[Assertion]
而不是ActorRef => Any
,而我们只扩展了AsyncFeatureSpec
而不是fixture.AsyncFeatureSpec