The MyFirstPlaySpec.scala
class should contain the following code:
class MyFirstPlaySpec extends PlaySpec { "x + 1 " must { "be 2 if x=1 " in { val sum = 1 + 1 sum mustBe 2 } "be 0 if x=-1 " in { val sum = -1 + 1 sum mustBe 0 } } }
So, you create a class called MyFirstPlaySpec
, and we extend it from PlaySpec
in order to get Play framework ScalaTest
support. Then we create two functions to test the sum of two numbers. In the first test, 1 +1
should be 2
, and in the second, -1 + 1
should be 0
. When we execute mustBe
, it is the same thing as doing an assert in Junit. The main difference here is that the test has behavior explicitly on the Spec. Now we can run the test by typing the following:
$ activator "test-only MyFirstPlaySpec"
You will see the following result...