2013-11-21 6 views
0

나는 grails를 사용하는 데있어 약간 익숙하므로 확실한 대답이 있다면 나에게 용서해주십시오. 새 컨트롤러를 만들 때 단위 테스트가 자동으로 작성되는 방법에 대한 설명서를 읽었습니다. 내가 온라인과 책에서 보았던 것에서 컨트롤러 테스트 클래스 이름 끝에 "test"가 추가되었습니다. 이 점에서 StoreControllerSpec.groovy 만든 \ 테스트 \ 장치 \ 디렉토리에 Grails는 2.3.1을 사용하여 내가 가진grails 단위 테스트를 만드는 법

@TestFor(StoreController) 
class StoreControllerSpec extends Specification { 

def setup() { 
} 

def cleanup() { 
} 

void testSomething() { 
\\ added to see if the test works 
controller.index() 
assert 'Welcome to the gTunes store!' == response.text 
} 
} 

나는 데 문제가 테스트 응용 프로그램을 실행하는 경우는 단위 테스트를 실행하려고한다는 것입니다하지만, 아무것도 출력하지 않으며 실패로 표시되지 않습니까?

grails> test-app 
| Running without daemon... 
| Compiling 1 source files 
| Compiling 1 source files. 
| Running 1 unit test... 
| Completed 0 unit test, 0 failed in 0m 4s 
| Tests PASSED - view reports in 

답변

0

이전 버전의 grails에서는 테스트가 포함 된 클래스가 "테스트"로 끝나야했습니다. 시도해 볼만한 가치가 있을까요?

예 :

Grails는 이제 기본적으로 스팍 테스트 프레임 워크를 사용하기 때문이다
void "test Something"() { 
controller.index() 
expect: 
"Welcome to the gTunes store!" == response.text 
} 

여기

+0

운이, 내가 클래스 이름을 변경하지 않고이 같은 일을했다 미안 – user2168435

1

내가 테스트 등을 작성하는 방법을 변경하여 문제를 해결하기 위해 관리되는 :

grails 2.3.x는 기본적으로 테스트 용으로 spock 프레임 워크를 사용합니다.

// Contro 크 로스 클래스

클래스 DomainListController {

def index() { 
    redirect (action:"list") 
} 

def list() { 
    render "hello" 
} 

}

// 테스트 클래스

@TestFor이 (DomainListController가) 클래스 DomainListControllerSpec이 사양을 확장 {

def setup() { 
} 

def cleanup() { 
} 

void "test something"() { 
} 

//test method to test index() of DomainListController 
def void testIndex() { 
    controller.index()    
    expect: 
    response.redirectedUrl == 'domainList/listll' 
} 

//test method to test list() of DomainListController 
def void testList() { 
    controller.list()  
      expect: 
    response.text == "hello" 
} 

}

-> @TestFor mixin이 contoller 조롱을 처리합니다. 컨트롤러를 인스턴스화하지 않고 컨트롤러, contoller.params, controller.request, controller.response와 같은 일부 키워드에 액세스 할 수 있습니다.

-> 응답 객체는 Spring의 MockHttpServletResponse 클래스를 확장하고 응답 상태를 검사하는 유용한 메소드가있는 GrailsMockHttpServletResponse (org.codehaus.groovy.grails.plugins.testing 패키지의) 인스턴스입니다. .

-> 예상은 :

희망이 당신 : 환호하는 데 도움이 예상 된 결과입니다 - Mothi을

+0

마우스 오른쪽 - 스팍 시험 방법 하나 이상의 라벨이 지정된 블록이 필요합니다. https://code.google.com/p/spock/wiki/SpockBasics를 참조하십시오. –

1

당신은 갈

class StoreControllerSpecTests extends Specification 
관련 문제