【问题标题】:Scala simple funsuite unit test with akka actors fails使用 akka 演员的 Scala 简单的 funsuite 单元测试失败
【发布时间】:2014-08-19 18:57:21
【问题描述】:

嘿,我想为 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

【问题讨论】:

    标签: scala testing akka actor testkit


    【解决方案1】:
    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"
    }
                   """
    }
    

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

    【讨论】:

      猜你喜欢
      • 2010-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-08
      • 1970-01-01
      • 2021-09-18
      • 2014-03-09
      • 1970-01-01
      相关资源
      最近更新 更多