当我运行用于测试演员的基本示例时:
class MySpec(_system: ActorSystem) extends TestKit(_system) with ImplicitSender
with WordSpec with MustMatchers with BeforeAndAfterAll {
我遇到了错误:class WordSpec needs to be a trait to be mixed in
我做错了什么?
WordSpec
的类和特质。该类名为WordSpec
,而特质是WordSpecLike
。因此,请改用WordSpecLike
而不是WordSpec
:class MySpec(_system: ActorSystem) extends TestKit(_system) with ImplicitSender
with WordSpecLike with MustMatchers with BeforeAndAfterAll {
import akka.testkit.TestKitBase
class MyTest extends TestKitBase {
implicit lazy val system = ActorSystem()
// put your test code here ...
shutdown(system)
}
隐式延迟值系统必须按照这样的方式声明(当然,您可以根据需要向Actor System工厂传递参数),因为TestKitBase特征需要在其构造期间使用该系统。
从 Scalatest 2.0 开始,你混入的 Specs 现在是类而不是特质。这意味着你不能与 Akka 的测试工具包一起使用它们... 因为它们都是类,你只能扩展其中一个。
切换到 scalatest 1.9.1。它仍然受到支持,并且是在他们进行更改并破坏 akka 用户之前发布的最后一个版本。在 1.9.1 中,specs 仍然是特质。
Like
后缀命名。例如WordSpecLike
。 - 1esha