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 8818371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:05:27+00:00 2026-06-14T05:05:27+00:00

I am trying folow the example from Mock Objects in Play[2.0] but unfortunately I

  • 0

I am trying folow the example from Mock Objects in Play[2.0] but unfortunately I am not having success.

I have a UsersController that uses a UserModel.

trait UserModel extends ModelCompanion[User, ObjectId] {
 // ...
}

Next, the abstract controller

abstract class UsersController extends Controller {

  val userModel: UserModel

  def sayHello = Action(parse.json) { request =>
    // return a play Action. Doesn't use userModel
  }


  // Other methods

}

In the routes file, I call method say Hello in this way:

POST /hello controllers.Users.sayHello

In test directory, I created a subclass of UsersController using a UserModel mock.

package controllers

import org.specs2.mock.Mockito

object UserControllersTest extends UsersController with Mockito {
  val userModel = mock[models.UserModel]
}

Now, the main part. I created a Spec test following the Jacob Groundwater example in the page mentioned before. In pluing argument for FakeApplication, I included a calling to UserControllersTest.

package controllers

import org.specs2.mutable.Specification

import play.api.libs.json.Json
import play.api.test._
import play.api.test.Helpers._

class UsersSayHelloSpec extends Specification {

  running(FakeApplication()) {

    "Users.SayHello" should {

      def sendJson(jsonMap: Map[String, String], shouldBeCorrect: Boolean) = {
        running(new FakeApplication(
          additionalPlugins = Seq("controllers.UserControllersTest"))) {
          // Preapration 
          val jsonRequisition = Json.toJson(jsonMap)
          val Some(result) = routeAndCall(FakeRequest(POST,
              "/hello",
              FakeHeaders(Map("Content-Type" -> Seq("application/json"))),
              jsonRequisition))

            // ...
        }
      }

      "Not process a empty String" in {
        sendJson(Map.empty[String, String], false)
      }

      // Other tests calling sendJson ...
    }

  }

}

However, when I run the test I got this error message:

[info] Users.SayHello should
[error] ! Not process a empty String
[error]     PlayException: Cannot load plugin [Plugin [controllers.UserControllersTest] cannot been instantiated.] (Application.scala:171)
...
[error] play.api.Application.<init>(Application.scala:158)
[error] play.api.test.FakeApplication.<init>(Fakes.scala:141)
[error] controllers.UsersSayHelloSpec$$anonfun$1$$anonfun$apply$5.sendJson$1(UsersSayHelloSpec.scala:20)
[error] controllers.UsersSayHelloSpec$$anonfun$1$$anonfun$apply$5$$anonfun$apply$26.apply(UsersSayHelloSpec.scala:46)
[error] controllers.UsersSayHelloSpec$$anonfun$1$$anonfun$apply$5$$anonfun$apply$26.apply(UsersSayHelloSpec.scala:46)

Where UsersSayHelloSpec.scala:20 referes to line where I call running method.

So my question is: What am I doing wrong?

  • 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-14T05:05:33+00:00Added an answer on June 14, 2026 at 5:05 am

    I’m not sure what exactly are you trying to do, but the answer for question ‘What am I doing wrong?’ is:

    The parameter ‘additionalPlugins’ is for additional Play plugins, and ‘controllers.UserControllersTest’ is not a Play plugin. It’s a Controller.

    You can read about Play 2 plugins here: http://www.objectify.be/wordpress/?p=464

    Have you tried these examples: http://www.playframework.org/documentation/2.0.4/ScalaFunctionalTest ?

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

Sidebar

Related Questions

I started to use moq but from my understanding I always have to mock
I have been trying to follow this example (download the source code from a
I have been trying to follow this example from propel to configure a custom
I'm trying to implement a simple TPH example from http://msdn.microsoft.com/en-us/library/dd793152.aspx . I have two
I am trying to follow this example (from p137 of Rob Pickering's Foundations of
I'm trying to follow the example on http://developers.cloudmade.com/wiki/iphone-sdk/Create_basic_Local_Search_and_Geocoding_app . The example from svn provided
I'm trying to follow some example code from microsofts mdn site.. var WshShell =
Trying to follow this example. (Section String sorting...) Is there anything obvious that would
I am new to maven and I am trying to follow this example but
I'm trying to follow the Auth example for Webapp2 that can be found here:

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.