2017-06-20 70 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方法來做到這一點。