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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:25:26+00:00 2026-05-27T07:25:26+00:00

I’m writing functional tests (geb + spock) for a Grails application, and want to

  • 0

I’m writing functional tests (geb + spock) for a Grails application, and want to have the app resolve a “mock” implementation of a Service when the app loads at test-time.

The ‘real’ version of the service communicates with a remote web serivce.

Ideally I’d have a mock implementation of this service that returns mock data (rather than going to the real, remote web service), and have this service be injected during the functional test runs.

Currently, the service is injected into controllers based on the standard naming convention technique, like so:

class BikeController {
    def myService
    def index = { render myService.doSomething() as JSON }
}

Is it possible to have something in my config, like:

environments {
    test {
        /* register myMockService to be used where myService normally would */
    }
}

(During unit testing I simply replace methods and do metaClass magic to accomplish these goals)

If I need to create an interface, OK, but still, how to wire it all up?
Thanks!

  • 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-27T07:25:27+00:00Added an answer on May 27, 2026 at 7:25 am

    There’s no support for an environments block in grails-app/conf/spring/resources.groovy but you can do an explicit environment check:

    import grails.util.Environment
    
    beans = {
    
        if (GrailsUtil.environment == 'test') {
           myService(com.myapp.MyMockService)
        }
    }
    

    Note that the service won’t be transactional, but if you need it to be it can be wrapped in a transactional proxy like Grails does for regular services. It might be simpler to just make transactional calls inside of a withTransaction block though since this is for testing only.

    • 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 have a French site that I want to parse, but am running into
I am writing an app with both english and french support. The app requests
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 want use html5's new tag to play a wav file (currently only supported

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.