Accepted answer

I decided to build a separate test project, and I used the activator to create a seed for the new project. I noticed that in the generated test that a different method of calling the action was used, so I switched my project to use this method. It worked, but I don't know why.

New code:

"should create a Company from a Json request" in new InMemoryDB {

  val newCompany = Company(name = "New Company1")

  val action = route(
    FakeRequest(POST, "/company")
      .withSession(("email", ""))
      .withHeaders(CONTENT_TYPE -> "application/json")

  status(action) should be_==(OK)
  (contentAsJson(action) \ "id").as[Long] should be_>(1L)


As you can see it uses a call to route instead of calling the controller.

Related Query

More Query from same tag