사용자 도구

사이트 도구


java:spock

문서의 이전 판입니다!


Spock

Dependencies

testCompile group: 'org.spockframework', name: 'spock-core', version: '1.0-groovy-2.4'
testCompile group: 'cglib', name: 'cglib-nodep', version: '3.2.4' // Class Mocking 할 때 필요.

Spock Feature Method 기본형태(test method)

// 일반적인 테스트
 
def "Feature Method name"() {
    :given "생략가능"
    // 테스트용 데이터 초기화
 
    :when
    // 테스트 대상 코드를 실행하고 실행 결과를 변수 등에 저장
 
    :then
    // 테스트 결과에 대한 검증.
    // 각 줄은 boolean 결과를 내는 Statement 로 작성한다.
    // 만약 한 줄의 코드가 boolean statement가 아니고 복잡한 구문일 경우에는 그 안의 assert boolean 구문에 'assert'를 붙여야한다.
}
 
// Data Driven 테스트
def "Feature method name #a - #b = #c"(변수 a, 변수 b, 변수 c) {
    expect:
    // 각 데이터 변수로 테스트 수행
 
    where: "각 데이터 변수 설정"
    a | b || c
    1 | 2 || 3
    4 | 5 || 6
}

Mock Argument Capture

How to do argument capture with spock framework? - Stack Overflow : 아이디어는 맞지만 실제 구현에 오류가 있다. 다음과 같이 수정.

SaveCommentEvent capturedEvent
 
given:
 ...
 
when:
 ....
 
then:
1 * eventBus.fireEvent({capturedEvent = it; true})
 
capturedEvent instanceof SaveModelEvent
capturedEvent.newModel == newModel
capturedEvent.oldModel == oldModel

참조

java/spock.1474955032.txt.gz · 마지막으로 수정됨: 2016/09/27 14:13 저자 kwon37xi