bdd with spock
TRANSCRIPT
BDD
With Spock
TDD를처음접할때고민
• http://dannorth.net/introducing-bdd/
TEST할때 5가지고민들
1. 어디서부터프로세스를시작해야되지?
2. 테스트여부를어떻게정하지?
3. 한번에얼만큼테스트해야되지?
4. 테스트를어떻게명명해야되지?
5. 테스트가실패하는이유를어떻게이해하지?
Behaviour DD
• 구체적으로의도를잘이해할수있도록시나리오를가지고명세화하자.
• 템플릿
1. Given ( 어떤값이할당되었을때 )
2. When ( 이벤트가발생했을때)
3. Then ( 결과는 ~ 여야한다.)
Mocking과는무슨차이?
• 이미쓰는데요expect( some.doing(ABC)).andReturn(True).times(2);
UML처럼개발자가아닌사람에게도
BDD in Action Manning
Spock
• Peter Niederwieser이 Groovy로만든 BDD 프레임워크
Spock 준비(Gradle)
Dependencies{
compile "org.codehaus.groovy:groovy-all:2.4.1"
testCompile"org.spockframework:spock-core:1.0-groovy-2.4"
}
Dependencies{
compile localGroovy()
testCompile
"org.spockframework:spock-
core:1.0-groovy-2.4"
}
OR
Spock준비(Maven)
Maven에서 Groovy지원을위한 GmavenPlus Maven plugin
전체내용
https://github.com/spockframework/spock-example/blob/master/pom.xml
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
Spock준비(Maven 2)
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.0-groovy-2.4</version>
<scope>test</scope>
</dependency>
<!-- Optional dependencies for using Spock -->
<dependency> <!-- use a specific Groovy version rather than the one specified by spock-core -->
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.1</version>
</dependency>
Start
Import spock.lang.*
start2
명세작성
Class MyFirstSpecification extends Specification{
fields
fixture methods
feature methods
helper methods
}
example1
• class HelloSpockSpec extends spock.lang.Specification {
• def "length of Spock's and his friends' names"() {
• expect:
• name.size() == length
• where:
• name <<["kirk", "spock", "scotty"]
• length <<[4, 5, 7]
• }
시나리오시작
예상하는결과
Spock의 where절
• Given
• When,
• Then
• 표준템플릿유형이고반드시이유형으로작성해야하는것은아님
Spock의 where절의유형
• Spock의 where절은 2가지경우에사용
순회해야할요소를가지고있거나,
시나리오안에데이터테이블을가지고있을때
Spock where usage
where:
name <<["kirk",
"spock", "scotty"]
length <<[4, 5, 7]
where:
Name | gender
‘sara’ | ‘W’
‘mike’ | ‘m’
‘stacy’ | ‘w’
Namelength =name.length()
Reference
• https://github.com/spockframework/spock-example