开发者

Grails Controller Testing - Problems with dynamic methods

开发者 https://www.devze.com 2023-01-15 02:05 出处:网络
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 forsome dymamic method\'

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: () v开发者_如何学运维alues: []

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


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

mockDomain Emp
0

精彩评论

暂无评论...
验证码 换一张
取 消