Writing a ScalaTest-based unit test

To demonstrate how the ScalaTest unit-testing library works, we will write a unit test for one actor. Add a ScalaTest test case by right-clicking on src/test/scala and choosing New | Scala Class. Name the QuotesHandlerActorTests class. Remove the generated code and start by defining the required imports and the class definition itself:

    import akka.actor.{ActorSystem, Props}    import akka.testkit.{TestKit, ImplicitSender, TestActorRef}    import org.scalatest.{Matchers, FlatSpecLike, BeforeAndAfterAll}    import akkaquote.actor.QuotesHandlerActor    import akkaquote.message.{AddQuote, Quote, QuoteAdded}    class QuotesHandlerActorTests()     extends TestKit(ActorSystem("Tests"))    with ImplicitSender with Matchers with FlatSpecLike ...

Get Introduction to JVM Languages now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.