views:

37

answers:

1

Hi,

I'm running some old (but valid, i'm told) tests on a legacy application, and notice that many of them arent working. The error message usually is 'No method signature for some dymamic method'

After using mockDomain I managed to solve that problem. However, I can't figure out how to test controllers that create objects inside.

For example, I created a sample controller (omitted import statements)

package com.tmp
class DummyController2 {

    def index = { }

    def createObject={
        def emp= new Emp(name:'name',description:'description')

        if (emp.validate()){
          render 'OK'
        }
        else{
          render 'FAIL'
        }
    }
}

And then the sample controllerTest

package com.tmp
class DummyController2Tests extends ControllerUnitTestCase{

  DummyController2 controller

  public void setUp(){
    super.setUp()
    controller = new DummyController2()
  }

  public DummyController2Tests(){
         super(DummyController2Tests)
  }
  public void tearDown(){
    super.tearDown()
  }

  void testCreateObject(){
    assertEquals 'OK',controller.createObject()
  }
}

Now when I run this test, I get the

groovy.lang.MissingMethodException: No signature of method: Emp.validate() is applicable for argument types: () values: []

Is there a workaround on this? Adding mockDomain statements inside the controller seems very intrusive and wrong. Maybe its just that I'm using an old grails (1.2.1)?

Thanks in advance

A: 

Your domain class is not mocked. Add to setUp():

mockDomain Emp
Stefan
java.lang.NullPointerException: Cannot invoke method containsKey() on null object
Tom
sorry, forgot about that one, you should use "MockUtils.mockLogging Emp"
Stefan