为什么它的类型为 Nothing?

Why it has the type Nothing?

我正尝试在我的 bdd 测试中使用 https://www.testcontainers.org/,如下所示:

final class DetectorSpec extends BddSpec {

  private val listener1 = TestProbe()
  private val listener2 = TestProbe()

  private val detector = system.actorOf(DetectorSupervisor.props)

  var sapMock = new FixedHostPortGenericContainer("zerocoder/sapmock:2.1.1")
    .withFixedExposedPort(8080, 9090)


  override def afterAll(): Unit = {
    TestKit.shutdownActorSystem(system)
  }
  ......

上面代码的问题是,变量 sapMock 的类型为 Nothing。看来,该方法链接不起作用。

为什么变量 sapMock 的类型是 Nothing

FixedHostPortGenericContainer 需要容器本身的 F-bounded 参数类型。您根本没有指定任何类型参数,所以看起来您最终得到了类似于原始类型的东西。

尝试

class SapMock extends 
FixedHostPortGenericContainer[SapMock]("zerocoder/sapmock:2.1.1")


val sapMock = new SapMock.withFixedExposedPort(8080, 9090)