使用org.scalatest测试Akka Actor

时间:2018-09-07 06:06:31

标签: akka actor scalatest

class Scheduler(repository : Repository) extends Actor
{
override def receive : Receive =
{
    case TriggerDaily => repository.deleteOlderThan1year()
    case TriggerHourly => repository.nullifyOlderThan3hrs()
}
}

object Scheduler
{
case object TriggerDaily
case object TriggerHourly

def props(repository : Repository) =
    Props(classOf[Scheduler], repository)

}

在此存储库中,方法deleteOlderThan1year和deleteOlderThan1year返回Future [Done]吗?谁能帮我如何为此Scheduler Actor编写单元测试用例?

1 个答案:

答案 0 :(得分:0)

查看documentation以测试Akka。本质上,您将扩展TestKit来为您的actor初始化一个actor系统。由于您的参与者需要使用Repository进行实例化,因此我还建议您研究模拟Repository来验证是否调用了适当的方法。