使用 akka actors 的 Scala 简单 funsuite 单元测试失败

标签 scala testing akka actor testkit

嘿,我想为 akka actor 应用程序构建一些小型 Funsuite 测试,但是在将 Testkit 与 FunSuiteLike 结合后,我不能再调用该测试了。 有人知道为什么会这样吗? Testkit 和 funsuite 不兼容吗?

import org.scalatest.{FunSuiteLike, BeforeAndAfterAll}
import akka.testkit.{ImplicitSender, TestKit, TestActorRef}
import akka.actor.{ActorSystem}

class ActorSynchroTest(_system: ActorSystem) extends TestKit(_system) with FunSuiteLike with BeforeAndAfterAll with ImplicitSender{


  val actorRef =  TestActorRef(new EbTreeDatabase[Int])
  val actor = actorRef.underlyingActor

  //override def afterAll = TestKit.shutdownActorSystem( system )

  test("EbTreeDatabase InsertNewObject is invoked"){
    val idList = List(1024L,1025L,1026L,1032L,1033L,1045L,1312L,1800L)
      idList.
      foreach(x => actorRef ! EbTreeDataObject[Int](x,x,1,None,null))
    var cursor:Long = actor.uIdTree.firstKey()
    var actorItems:List[Long] = List(cursor)

    while(cursor!=actor.uIdTree.lastKey()){
      cursor = actor.uIdTree.next(cursor)
      cursor :: actorItems
    }
    assert(idList.diff(actorItems)  == List())
  }
}

intelliJ idea 测试环境说:

One or more requested classes are not Suites: model.ActorSynchroTest

最佳答案

class ActorSynchroTest extends TestKit(ActorSystem("ActorSynchroTest",ConfigFactory.parseString(ActorSynchroTest.config)))
with DefaultTimeout with ImplicitSender
with FunSuiteLike with Matchers with BeforeAndAfterAll  {
 ...

}

object ActorSynchroTest {
  // Define your test specific configuration here
  val config = """
akka {
loglevel = "WARNING"
}
               """
}

在使用不适合的标准配置之前,testkit 的不同初始化最终起作用

关于使用 akka actors 的 Scala 简单 funsuite 单元测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25390986/

相关文章:

ruby-on-rails-3 - Rails - 更改了表名,现在测试不会运行

scala - Akka DistributedPubSubMediator at-least-once delivery guarantees for publishing to a topic

arrays - 如何在 scala 中的二维数组上使用 contains 方法

scala - 找不到参数 lgen : shapeless. LabelledGeneric.Aux 的隐式值

Scala SyncVar isDefined 标志的使用

testing - 对部分模拟的期望 - NullReference 异常

scala - 如何强制重新编译调用宏的类?

php - 使用 Android 应用程序在本地测试 PHP Web 服务

scala - 如何配置 Akka Pub/Sub 在同一台机器上运行?

java - 将 Akka 源代码转换为 RxJava2 Flowable?