Improve Getting Started Guide Part 3 for writing a first Actor test #25193

This commit is contained in:
Oliver Burkhalter 2018-11-15 12:55:29 +01:00 committed by Johan Andrén
parent fb326b7f01
commit 40483a2506
9 changed files with 13 additions and 10 deletions

View file

@ -37,7 +37,7 @@ We create child, or non-top-level, actors by invoking `context.actorOf()` from a
The easiest way to see the actor hierarchy in action is to print `ActorRef` instances. In this small experiment, we create an actor, print its reference, create a child of this actor, and print the child's reference. We start with the Hello World project, if you have not downloaded it, download the Quickstart project from the @scala[[Lightbend Tech Hub](http://developer.lightbend.com/start/?group=akka&project=akka-quickstart-scala)]@java[[Lightbend Tech Hub](http://developer.lightbend.com/start/?group=akka&project=akka-quickstart-java)].
In your Hello World project, navigate to the `com.lightbend.akka.sample` package and create a new @scala[Scala file called `ActorHierarchyExperiments.scala`]@java[Java file called `ActorHierarchyExperiments.java`] here. Copy and paste the code from the snippet below to this new source file. Save your file and run `sbt "runMain com.lightbend.akka.sample.ActorHierarchyExperiments"` to observe the output.
In your Hello World project, navigate to the `com.example` package and create a new @scala[Scala file called `ActorHierarchyExperiments.scala`]@java[Java file called `ActorHierarchyExperiments.java`] here. Copy and paste the code from the snippet below to this new source file. Save your file and run `sbt "runMain com.example.ActorHierarchyExperiments"` to observe the output.
Scala
: @@snip [ActorHierarchyExperiments.scala](/akka-docs/src/test/scala/tutorial_1/ActorHierarchyExperiments.scala) { #print-refs }

View file

@ -20,7 +20,7 @@ represent devices and dashboards at the top level. Instead, we recommend creatin
We can define the first actor, the IotSupervisor, with a few simple lines of code. To start your tutorial application:
1. Create a new `IotSupervisor` source file in the `com.lightbend.akka.sample` package.
1. Create a new `IotSupervisor` source file in your appropriate package, e.g. in the `com.example` package
1. Paste the following code into the new file to define the IotSupervisor.
Scala

View file

@ -146,8 +146,11 @@ Note in the code that:
## Testing the actor
Based on the simple actor above, we could write a simple test. In the `com.lightbend.akka.sample` package in the test tree of your project, add the following code to a @scala[`DeviceSpec.scala`]@java[`DeviceTest.java`] file.
@scala[(We use ScalaTest but any other test framework can be used with the Akka Testkit)].
Based on the simple actor above, we could write a simple test. You can check a full example of an Actor test in the Quickstart guide here @scala[[Quickstart Guide Testing example](https://developer.lightbend.com/guides/akka-quickstart-scala/testing-actors.html)] @java[[Quickstart Guide Testing example](https://developer.lightbend.com/guides/akka-quickstart-java/testing-actors.html)].
You'll find there an example on how you can fully setup an Actor test, so that you can run it properly.
In the test tree of your project, add the following code to a @scala[`DeviceSpec.scala`]@java[`DeviceTest.java`] file.
@scala[(We use [ScalaTest](http://www.scalatest.org) but any other testing framework can be used with the Akka Testkit)].
You can run this test @java[by running `mvn test` or] by running `test` at the sbt prompt.

View file

@ -3,7 +3,7 @@
*/
//#print-refs
package com.lightbend.akka.sample;
package com.example;
//#print-refs

View file

@ -3,7 +3,7 @@
*/
//#iot-app
package com.lightbend.akka.sample;
package com.example;
import java.io.IOException;

View file

@ -3,7 +3,7 @@
*/
//#iot-supervisor
package com.lightbend.akka.sample;
package com.example;
import akka.actor.AbstractActor;
import akka.actor.ActorLogging;

View file

@ -6,7 +6,7 @@
package docs.tutorial_1
//#print-refs
package com.lightbend.akka.sample
package com.example
import akka.actor.{ Actor, Props, ActorSystem }
import scala.io.StdIn

View file

@ -5,7 +5,7 @@
package tutorial_2
//#iot-app
package com.lightbend.akka.sample
package com.example
import akka.actor.ActorSystem
import scala.io.StdIn

View file

@ -5,7 +5,7 @@
package tutorial_2
//#iot-supervisor
package com.lightbend.akka.sample
package com.example
import akka.actor.{ Actor, ActorLogging, Props }