10 maj 2014 kl. 16:11 skrev Carsten Saathoff <[email protected]>:

> Hi Roland,
> 
> Am Freitag, 9. Mai 2014 15:32:30 UTC+2 schrieb rkuhn:
> The failure modes of an actor do make sense to view as part of its API, it is 
> something the supervisor will have to know about and prepared to handle (or 
> escalate). Therefore I agree with the sentiment that it should be testable as 
> well. What I use is what I call a StepParent actor that looks like this:
> 
> Yes, after further thinking about it, I also came to the same conclusion.
>  
> class StepParent(target: ActorRef) extends Actor {
>   override val supervisorStrategy = OneForOneStrategy() {
>     case thr: Throwable => target ! thr; Restart // or make it 
> configurable/controllable during the test
>   }
>   def receive = {
>     case p: Props => sender ! context.actorOf(p, "child")
>   }
> }
> 
> ... // in a test
> val parent = system.actorOf(Props(new StepParent(testActor)), "stepParent")
> parent ! Props(...) // for the actor under test
> val subject = expectMsgType[ActorRef]
> // and now test the subject
> 
> That's actually very similar to how I tested whether exceptions are thrown. 
> But I also wondered whether it would be possible to make this more 
> convenient. For instance some method on TestActorRef that can be used to 
> check if and what exceptions were thrown. Or are there technical limitations 
> that this is not supported?

That is the purpose of `TestActorRef.receive(msg, sender)`, but the restriction 
is that it covers only message processing which comes directly from the test 
procedure. In general you should not care which actors are involved and whether 
your actor under test delegates a task to a temporary child actor: you should 
only test the externally visible behavior, which means running the actor in its 
natural habitat. That is what we mean when saying that unit testing is mostly a 
waste of time: you should concentrate on functional tests. OTOH I would love to 
redefine “unit testing” to mean “functional testing of a unit” (which 
conveniently is one actor, including its descendants).

Regards,

Roland

> 
> best
> 
> Carsten
> 
> -- 
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ: 
> >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.



Dr. Roland Kuhn
Akka Tech Lead
Typesafe – Reactive apps on the JVM.
twitter: @rolandkuhn


-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to