akka 无法使用夹具覆盖(测试:一个参数测试)

nkoocmlb  于 2022-11-06  发布在  其他
关注(0)|答案(3)|浏览(138)
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.对象套件不是软件包org.scalatest.fixture的成员注意:trait Suite存在,但没有伴随对象。
1.未找到:类型OneArgTest

szqfcxe2

szqfcxe21#

而不是混合特性“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) = {}
}

这解决了问题。

ct3nt3jp

ct3nt3jp2#

您需要使用org.scalatest. flatspec.

import org.scalatest.flatspec.FixtureFlatSpecLike

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

o75abkj43#

只需删除导入即可。OneArgTestSuite trait中的内部保护trait,因此它可以在Suite的后代中使用,而无需导入。

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

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

相关问题