Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Akka中持久参与者的单元测试_Java_Unit Testing_Akka_Actor - Fatal编程技术网

Java Akka中持久参与者的单元测试

Java Akka中持久参与者的单元测试,java,unit-testing,akka,actor,Java,Unit Testing,Akka,Actor,一个单元如何测试持久参与者。我知道有一个akka testkit可以用来获取测试参与者引用的底层参与者对象,如下所示 final TestActorRef<MyActor> ref = TestActorRef.create(system, props, "testA"); final MyActor actor = ref.underlyingActor(); assertTrue(actor.testMe()); final TestActorRef=TestActorRef.

一个单元如何测试持久参与者。我知道有一个akka testkit可以用来获取测试参与者引用的底层参与者对象,如下所示

final TestActorRef<MyActor> ref = TestActorRef.create(system, props, "testA");
final MyActor actor = ref.underlyingActor();
assertTrue(actor.testMe());
final TestActorRef=TestActorRef.create(系统,道具,“测试”);
最终MyActor=参考参考underlyingActor();
assertTrue(actor.testMe());
但这对前面提到的持久参与者不起作用


问题:一个单元如何测试持久参与者方法?

邮件列表中已经回答了这个问题。我将对这里给出的答案进行详细说明

测试参与者时,不应过度使用TestActorRef。最佳实践是通过向参与者发送和接收消息,尽可能多地进行测试。即使使用TestActorRef,您通常也会在通过发送和接收消息再次测试所需内容之前使用它来更改参与者的状态。实际上并不推荐使用对actor的直接访问来直接调用方法。如果在你的角色中有一些更复杂的逻辑,你需要单独测试,你可以考虑把它放进一个特性或不同的类中,并且在没有演员的情况下测试它。 对于正在开发的PersistentActors测试工具包,您可以跟踪进度