Desktop version

Home arrow Computer Science arrow Building Applications with Scala



Your review_index.scala.html file should contain the following code:

@(reviews:Seq[Review])(implicit flash: Flash) @main("Reviews") {

@if(!reviews.isEmpty) {

@for(review <- reviews) {


ProductId Author Comment

details(">@review.productId @review.comment


success">Add Review


Finally, we can run the tests on the console.

$ activator "test-only ReviewControllerTestSpec"

The test will show the following output:

Alright, ReviewController has passed all our tests. It's a very good practice to have the tests separated by type. However, if you want, you could mix all the tests such as unit testing, controller testing, and route testing in one single file.


Your ApplicationSpec.scala should have the following code:

class ApplicationSpec extends PlaySpec with OneAppPerTest { "Routes" should {

"send 404 on a bad request" in {

route(app, FakeRequest(GET, "/boum")).map(status(_)) mustBe Some(NOT_FOUND)



"HomeController" should {

"render the index page" in {

val home = route(app, FakeRequest(GET, "/")).get status(home) mustBe OK

contentType(home) mustBe Some("text/html")

contentAsString(home) must include ("Welcome to Reactive Web Store")



"RndController" should {

"return a random number" in {

// Assuming ng-microservice is down otherwise will fail. contentAsString(route(app, FakeRequest(GET, "/rnd/rxbat")).get) mustBe "2.3000000000000007"




We can run these mixed tests, and they will all pass.

$ activator "test-only ApplicationSpec"

You will see this result:

OK, we are almost done. We just need to add some tests for the microservice called ng-

microservice , which we created in chapter 4, Developing Reactive Backing Services.

Found a mistake? Please highlight the word and press Shift + Enter  
< Prev   CONTENTS   Next >

Related topics