Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8377103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:34:48+00:00 2026-06-09T15:34:48+00:00

I am trying to test an action on a controller. It’s a rather simple

  • 0

I am trying to test an action on a controller.

It’s a rather simple action, it takes JSON and returns JSON:

  def createGroup = Action(parse.json) { request =>
    val name = (request.body \ "name").as[String]
    val collabs = (request.body \ "collabs").as[List[String]]


    Ok(Json.toJson(
      Map("status" -> "OK",
        "message" -> "%s created".format(name))
    ))
  }

I want to verify that the JSON returned is indeed correct.

How would I use FakeRequest to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:34:49+00:00Added an answer on June 9, 2026 at 3:34 pm

    Maybe something like:

    "POST createGroup with JSON" should {
      "create a group and return a message" in {
        implicit val app = FakeApplication()
        running(app) {
          val fakeRequest = FakeRequest(Helpers.POST, controllers.routes.ApplicationController.createGroup().url, FakeHeaders(), """ {"name": "New Group", "collabs": ["foo", "asdf"]} """)
    
          val result = controllers.ApplicationController.createGroup()(fakeRequest).result.value.get
    
          status(result) must equalTo(OK)
          contentType(result) must beSome(AcceptExtractors.Accepts.Json.mimeType)
    
          val message = Region.parseJson(contentAsString(result))
    
          // test the message response
        }
      }
    }
    

    Note: The val result line might now be correct since I took it from a test that uses an Async controller.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Controller: def test = Action { implicit request => import play.api.i18n._ val msg =
I'm trying to test a rails action that takes raw json in the POST
I am trying to unit test a controller action that uses UpdateModel but I
I am trying to test a controller action that allows edition of user profiles.
I am running on Castle's trunk, and trying to unit-test a controller-action where validation
I am trying to test my controller's create action. I am using Devise for
I'm trying to write a test for an ASP.Net MVC controller action. I'd like
I am trying to test a controller function that accepts a json payload. As
Below is my action in the controller. I am trying to test this action
I'm trying to test a link that calls a controller action using ajax. Essentially,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.