无法覆盖withFixture(test:OneArgTest)

时间:2016-04-23 12:25:32

标签: scala akka actor

import org.scalatest.fixture.Suite.OneArgTest

class PingPongActorSpec extends TestKit(ActorSystem("PingPongActorSpec")) 
  with ImplicitSender with FlatSpecLike with Matchers with BeforeAndAfterAll {

  override def withFixture(test: OneArgTest) = {}
}

当我尝试使用类型' OneArgTest'的测试覆盖withFixture方法时编译器给我以下错误消息:

  1. object Suite不是包org.scalatest.fixture的成员注意:trait Suite存在,但它没有配套对象。
  2. 未找到:输入OneArgTest

3 个答案:

答案 0 :(得分:1)

您需要使用 org.scalatest.flatspec.FixtureFlatSpecLike

import org.scalatest.flatspec.FixtureFlatSpecLike

class PingPongActorSpec extends TestKit(ActorSystem("PingPongActorSpec")) 
      with ImplicitSender with FixtureFlatSpecLike with Matchers with BeforeAndAfterAll { ...

答案 1 :(得分:0)

只需删除您的导入。 OneArgTestSuite特征中的内部受保护特征,因此可以在套件的后代中使用而无需导入。这个 应该工作:

class PingPongActorSpec extends TestKit(ActorSystem("PingPongActorSpec")) 
  with ImplicitSender with FlatSpecLike with Matchers with BeforeAndAfterAll {

  override def withFixture(test: OneArgTest) = {}
}

答案 2 :(得分:0)

而不是混合特性“ FlatSpecLike ”:

class PingPongActorSpec extends TestKit(ActorSystem("PingPongActorSpec")) 
  with ImplicitSender with FlatSpecLike with Matchers with BeforeAndAfterAll  {
  override def withFixture(test: OneArgTest) = {}
}

我们需要混合特质“ fixture.FlatSpecLike ”:

class PingPongActorSpec extends TestKit(ActorSystem("PingPongActorSpec")) 
  with ImplicitSender with fixture.FlatSpecLike with Matchers with BeforeAndAfterAll
  override def withFixture(test: OneArgTest) = {}
}

这解决了这个问题。