Testing is the process of cross-checking the implementation of an application/process. It brings its shortcomings out into the open. It can be extremely handy when you are upgrading/downgrading one or more dependencies. Tests can be classified into various categories based on different programming practices, but in this chapter, we will only discuss two types of tests:
In the following sections, we will see the different ways in which we can test a Play application using Specs2 and ScalaTest.
The tests using either of the Specs2 and ScalaTest libraries are similar. The major difference is in the keywords, syntax, and style. Since different developers can have different preferences, in this chapter, tests are defined using both libraries and for convenience. Most of the tests written using Specs2 have names ending with 'Spec'
, while those using ScalaTest end with 'Test'
.
Play is packaged with Specs2
, since this is the library used internally for testing it. It provides support to test applications using Specs2 by default, that is, no additional library dependency is required.
Using ScalaTest
earlier was difficult but now, Play also provides helpers for using ScalaTest. Although it is picked up from transitive dependencies, we need to add a library dependency to use the helper methods:
val appDependencies = Seq( "org.scalatestplus" %% "play" % "1.1.0" % "test" )
The 1.1.0 version of org.scalatestplus.play
is compatible with Play 2.3.x. It is better to check the compatibility when working with another version of Play at http://www.scalatest.org/plus/play/versions.
18.118.205.235