2017-06-20 69 views
1

的actionName一个拦截器的before()我在做具体的基础上,actionName的东西,但在测试运行时actionName为空:如何使可用于单元测试

测试:

void "test"() { 
    when: 
     withRequest(controller: 'test1', action: 'test2') 

    then: 
     interceptor.doesMatch() 
     interceptor.before() 
} 

如何在测试中填充actionName

的Grails 3.1.6

回答

0
void "test"() { 
    when: 
     withRequest(controller: 'test1', action: 'test2') 
     request.setAttribute(GrailsApplicationAttributes.ACTION_NAME_ATTRIBUTE, 'test2') 

    then: 
     interceptor.doesMatch() 
     interceptor.before() 
} 

这对我的作品,但我宁愿更自动化的方式,我预计withRequest方法来做到这一点。