1

I am working on Unit Tests for a groovy n grails application v-2.1.1

I have a createCriteria() to mock, which looks like below controller code snippet:

  def updateList = {
    def Cr = Book.createCriteria()

    def Find = Cr.list() {
      and {
        eq ("name", params.name)
        eq ("age", params.age)
        eq ("prop", params.prop) 
      }
    }
  }

My test method looks like:

void testUpdateList(){
  try{
    controller.request.method = 'POST'
    controller.session.userName = "amy"
    controller.params.name = "A1"
    controller.params.age = "four"
    controller.params.prop = "D1"
    controller.updateList()     
  }catch(Exception ex){
    ex.printStackTrace()
  }
}

I am able to pass params to the controller method through my test method. Can you please help me in mocking createCriteria() whith an example of Mocking the data so that I can validate it?

Thanks in advance amy

Amy PrIce
  • 47
  • 1
  • 7

1 Answers1

0

I think the code snippets in this question: groovy / grails / unit testing / createCriteria.get

will show you what you need to do, roughly

Community
  • 1
  • 1
Jiminyjetson
  • 121
  • 1
  • 6