我有一个Controller类,它控制发送给注入控制器的Akka actor的请求。
控制器代码:
$(function() {
$('.report-icon-list .cht-add').on("click",function(){
var td = $(this).parent().parent();
var $i = td.index();
td.after("<td>discription</td>");
$("#sorting tr.headerrow > th:eq(" + $i + ")").after("<th>heading</th>");
});
})
我的演员代码是:
class Controller(actor: ActorRef) {
def control(msg: String): Future[String] = {
actor.ask(msg)(Timeout(2 seconds)).mapTo[String]
}
}
现在我需要将ActorA的行为模拟为单元测试Controller。有没有办法通过Akka TestKit这样做?
答案 0 :(得分:9)
使用TestProbe
。来自testing documentation:
val probe = TestProbe()
val future = probe.ref ? "hello"
probe.expectMsg(0 millis, "hello")
probe.reply("world")
assert(future.isCompleted && future.value == Some(Success("world")))