0

Grails documentation도메인 클래스 용 통합 테스트를 REST 리소스로 작성하는 방법은 무엇입니까?

에서처럼 도메인 클래스를 사용하고 있습니다. 따라서이 접근법을 사용하는 동안 생성 된 컨트롤러 또는 서비스 클래스가 없습니다. 그리고 도메인에 대한 통합 테스트를 REST 리소스로 쓰려고했지만 찾을 수 없었습니다. 친절하게 말해서 어떻게하는지 말해 주거나 같은 것을 말해주는 링크를 게시하십시오.

이 접근법에 관해서는 REST 서비스를 사용하는 다른 방법으로 변경할 수 없도록 만드는 것이 정확한 접근법입니다.

미리 감사드립니다.

답변

2

당신은 당신의 테스트 프레임 워크로 스팍을 사용하는 것이 좋습니다 :

class ExampleWebAppSpecification extends Specification { 
    def "Should return 200 & a message with the input appended"() { 

     setup: 
      def primerEndpoint = new RESTClient('http://localhost:8080/') 
     when: 
      def resp = primerEndpoint.get([ path: 'exampleendpoint', query : [ input : 'Get a hair cut' ]]) 
     then: 
      with(resp) { 
       status == 200 
       contentType == "application/json" 
      } 
      with(resp.data) { 
       payload == "Something really important: Get a hair cut" 
      } 
    } 
} 

편집 - buildConfig.groovy에서 :
https://spock-framework.readthedocs.org/en/latest/

예 REST를 위해 그것을 사용하는 방법

compile("org.codehaus.groovy:groovy-all:2.2.0") 
compile("com.fasterxml.jackson.core:jackson-databind") 

testCompile("org.spockframework:spock-core:0.7-groovy-2.0") 
testCompile("org.codehaus.groovy.modules.http-builder:http-builder:0.7+") 
testCompile("net.sf.json-lib:json-lib:2.4+") 
+0

답장을 보내 주셔서 감사합니다. 설치 한 플러그인 및 플러그인을 알려주십시오. 왜냐하면이 RESTClient 클래스는 기본적으로 사용할 수 없기 때문입니다. – Chetan

+1

buildConfig.groovy :'compile ': rest-client-builder : 2.0.3 "' – roeygol

+0

네, 실제로 이전에 Google을 확인한 후에 그랬습니다. 그러나 아직 많이 찾은 후에도 해결되지 않은 문제가 하나 있는데, buildConfig에 추가하고 설치할 앱을 실행할 때입니다. 그렇다하더라도 그것은 나에게와 오류를 보여줍니다 빨간색 underline-'그루비 : – Chetan