2014-06-19 1 views
0
 class ProjectDashBoardController { 
/* 
* This method is used to display project implementation's overview. 
*/ 
def check() { 
    render "Hello" 
} 

는이 다음 작업을 렌더링하기 때문에 테스트가 실패 컨디셔닝 대신 그러한 오류 방법 없음 서명을 보여주는, 내 통합 테스트assertEquals controller.action() return null ....! COM :

package com.spock 

import grails.plugin.spock.IntegrationSpec 

class ProjectDashBoardControllerIntegrationSpec extends IntegrationSpec { 

ProjectDashBoardController controller = new ProjectDashBoardController() 

def cleanup() { 
} 

void "test check action"() { 

    when: 
    controller.check() 

    then: 
    controller.check() 
    assertEquals "/dashboard/index", controller.response.redirectedUrl 


} 

}를 따라

입니다. (java.lang.String, null) 값 : [/ dashboard/index, null]

+0

Graeme의 답변을 수정하십시오. 또한 도움이된다면 대답을 받아 들여라. :) – dmahapatro

답변

2

스 톡에는 assertEquals 메 토가 없습니다. 스팍를 사용하는 경우 D, 당신은 assertthen 블록에서 암시하지만, 일반 그루비 전원이 주장 사용해야합니다

assert "/dashboard/index" == controller.response.redirectedUrl 

를 귀하의 경우에는 당신이해야합니까 불구하고 테스트 할 수있는 리디렉션 시나리오가 있습니다. 실제로 테스트해야하는 것은 응답이 렌더링 된 텍스트로 구성되어 있다는 것입니다.

void "test check action"() { 
    when: 
    controller.check() 

    then: 
    // Note there is no need to explicitly specify assert in then block 
    // Assertion is implicit 
    controller.response.text == "Hello" 
} 
+0

나는 assert와 assertEquals를 시도했다. 그러나 null로 동작을 리턴한다 ... – roanjain

+1

사실 액션은 null을 리턴하고, render 메소드에는 리턴 값이 없다. render 메소드가 응답에 쓰므로 "response.text"의 값을 지정해야합니다. –