O'Reilly logo

Introduction to JVM Languages by Vincent van der Leun

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required