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

  • SEARCH
  • Home
  • 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 6342019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:09:26+00:00 2026-05-24T20:09:26+00:00

I’m working on a play app and want to improve my test coverage before

  • 0

I’m working on a play app and want to improve my test coverage before going too far with the project.
So far I have quite good test coverage on the model layer, but the controllers tend to get a lot of logic in them (accumulating stuff and calculating from the model results).

Does anyone have a suggestion on how to structure my application so that all parts are easily testable? I could of course refactor all the logic out of the controller and only have one call to a different class for each controller method and then only use the render methods in the controller, but it seems a bit drastic.

Is there a way I can look at the results after a method has been run in the controller, e.g

public static void controllerMethod(String a){
    String result = doSomething();
    String calcResult = calculateSomething(a);
    render(result, calcResult)
}

How can I test that after this method the expected result and calcResult is what I want it to be in a unittest?

All the examples on the play site is about testing the model layer. I know I can run Functional tests towards the controller, but that is a bit to shallow for what I want to test.

If you have any suggestions about how I can structure my classes in order to have an easily testable application, please let me know.

  • 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-05-24T20:09:27+00:00Added an answer on May 24, 2026 at 8:09 pm

    Controllers task should be (mostly) control of the flow of the application (which page to show next). For that you can use the selenium tests in Play.

    If you find yourself adding a lot of login in the controller, either move it to methods in the related model (if applicable) or create a middle layer (ala Services) that manages the complex parts. They will be easier to test than Controllers, and will let you reuse the logic on several controllers (for example, acess via browser of REST API call)

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.