Unit testing Play Framework components
In this section, we will discuss how to unit test Play Framework components, using ScalaTest and its associated ScalaTest Plus unit testing frameworks.
Test HelloWorld without using DI Controller
In this section, we are going to refer play-scala-helloworld-app Play Scala-based HelloWorld application available in the Chapter-6 folder from the GitHub repository (https://github.com/rposa-srp-book/srp-book-examples/tree/master/Chapter-6/play-scala-helloworld-app) and write unit tests for its controller.
Perform the following steps to write unit tests for this application:
- Add the following entry in the
build.sbtfile available in the root folder of this project:
libraryDependencies ++= Seq(
"org.scalatestplus.play" %% "scalatestplus-play" % "1.5.1" % Test
) Here, we have configured the ScalaTest Plus unit testing framework in the Test scope. It provides all the required components to test Play Framework applications.
- Execute the
sbt update...