如何在 AsyncFeatureSpec 中使用 loan-fixture 方法?

How to use loan-fixture method with AsyncFeatureSpec?

如何将 loan-fixture 方法与 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)
      }
    }
  }
}

我不知道,如何注入贷款方法。

尝试以下方法

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