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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:23:07+00:00 2026-06-15T09:23:07+00:00

I am creating unit test for this (working fine) Grails service : class CommonCodeService

  • 0

I am creating unit test for this (working fine) Grails service :

class CommonCodeService {

    def gridUtilService

    def getList(def params){
        def ret = null

        try {
            def res = gridUtilService.getDomainList(CommonCode, params)
            def rows = []
            def counter = 0
            res?.rows?.each{ // this is line 15
                rows << [
                        id: counter ++,
                        cell:[

                            it.key,  
                            it.value  
                        ]
                ]
            }

            ret = [rows: rows, totalRecords: res.totalRecords, page: params.page, totalPage: res.totalPage]

        } catch (e) {
            e.printStackTrace()
            throw e
        }

        return ret
    }

}

This a method from collaborator GridUtilService :

import grails.converters.JSON

class GridUtilService {

    def getDomainList(Class domain, def params){
        /* some code */
        return [rows: rows, totalRecords: totalRecords, page: params.page, totalPage: totalPage]
    }
}

And this is my (not working) unit test for it :

import grails.test.mixin.TestFor
import grails.test.mixin.Mock
import com.emerio.baseapp.utils.GridUtilService

@TestFor(CommonCodeService)
@Mock([CommonCode,GridUtilService])
class CommonCodeServiceTests {

    void testGetList() {
        def rowList = [new CommonCode(key: 'value', value: 'value')]
        def serviceStub = mockFor(GridUtilService)
        serviceStub.demand.getDomainList {Map p -> [rows: rowList, totalRecords: rowList.size(), page:1, totalPage: 1]}
        service.gridUtilService = serviceStub.createMock()
        service.getList() // this is line 16
    }

}

When I run the test it shows exception :

No such property: rows for class: com.emerio.baseapp.CommonCodeServiceTests
groovy.lang.MissingPropertyException: No such property: rows for class: com.emerio.baseapp.CommonCodeServiceTests
    at com.emerio.baseapp.CommonCodeService.getList(CommonCodeService.groovy:15)
    at com.emerio.baseapp.CommonCodeServiceTests.testGetList(CommonCodeServiceTests.groovy:16)

It seems the mocked GridUtilService returns CommonCodeServiceTests instance instead of Map. What is wrong with my unit test?

  • 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-15T09:23:08+00:00Added an answer on June 15, 2026 at 9:23 am

    It looks like you need to fix your method params for the mocked getDomainList() call. You have it as Map m, but it probably needs to be Class c, Map m.

    From docs,

    The closure arguments must match the number and types of the mocked method, but otherwise you are free to add whatever you want in the body.

    Why a miss on the arguments behaves the way it does is a stumper. I can replicate your problem using my own stripped-down classes. I also found that the returned type for a call on the method when there’s a param miss is a closure of the test class, which, for my simple case at least, can then be .call()‘ed to get the desired (mocked) result. I’m not sure if this behavior supports some kind of functionality or is a bug. It’s certainly confusing.

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

Sidebar

Related Questions

What ways do I have for creating a unit test template like this? I'm
I am creating a unit testing project for my application. It was working fine
so I'm currently creating a unit test for a class that I've implemented a
I am new to use moq. I am into creating some unit test case
I am creating unit tests with DUnit. I have a class that takes quite
now i'm working on a project for creating audio unit instrument that provide the
I want to write unit test for a class that contains linq to sql
I'm currently creating a paired unit test assembly for every assembly in my project,
Im doing some test creating an instance of HTMLDocument this way: object[] pageText =
After some hours creating a vb.net helper class for unit-tests and integrating moq into

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.