bdd with spock
TRANSCRIPT
![Page 1: BDD with Spock](https://reader034.vdocuments.mx/reader034/viewer/2022050723/55a697371a28ab752d8b46ec/html5/thumbnails/1.jpg)
BDD
With Spock
![Page 2: BDD with Spock](https://reader034.vdocuments.mx/reader034/viewer/2022050723/55a697371a28ab752d8b46ec/html5/thumbnails/2.jpg)
TDD를처음접할때고민
• http://dannorth.net/introducing-bdd/
TEST할때 5가지고민들
1. 어디서부터프로세스를시작해야되지?
2. 테스트여부를어떻게정하지?
3. 한번에얼만큼테스트해야되지?
4. 테스트를어떻게명명해야되지?
5. 테스트가실패하는이유를어떻게이해하지?
![Page 3: BDD with Spock](https://reader034.vdocuments.mx/reader034/viewer/2022050723/55a697371a28ab752d8b46ec/html5/thumbnails/3.jpg)
Behaviour DD
• 구체적으로의도를잘이해할수있도록시나리오를가지고명세화하자.
• 템플릿
1. Given ( 어떤값이할당되었을때 )
2. When ( 이벤트가발생했을때)
3. Then ( 결과는 ~ 여야한다.)
![Page 4: BDD with Spock](https://reader034.vdocuments.mx/reader034/viewer/2022050723/55a697371a28ab752d8b46ec/html5/thumbnails/4.jpg)
Mocking과는무슨차이?
• 이미쓰는데요expect( some.doing(ABC)).andReturn(True).times(2);
![Page 5: BDD with Spock](https://reader034.vdocuments.mx/reader034/viewer/2022050723/55a697371a28ab752d8b46ec/html5/thumbnails/5.jpg)
UML처럼개발자가아닌사람에게도
BDD in Action Manning
![Page 6: BDD with Spock](https://reader034.vdocuments.mx/reader034/viewer/2022050723/55a697371a28ab752d8b46ec/html5/thumbnails/6.jpg)
Spock
• Peter Niederwieser이 Groovy로만든 BDD 프레임워크
![Page 7: BDD with Spock](https://reader034.vdocuments.mx/reader034/viewer/2022050723/55a697371a28ab752d8b46ec/html5/thumbnails/7.jpg)
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
![Page 8: BDD with Spock](https://reader034.vdocuments.mx/reader034/viewer/2022050723/55a697371a28ab752d8b46ec/html5/thumbnails/8.jpg)
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>
![Page 9: BDD with Spock](https://reader034.vdocuments.mx/reader034/viewer/2022050723/55a697371a28ab752d8b46ec/html5/thumbnails/9.jpg)
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>
![Page 10: BDD with Spock](https://reader034.vdocuments.mx/reader034/viewer/2022050723/55a697371a28ab752d8b46ec/html5/thumbnails/10.jpg)
Start
Import spock.lang.*
![Page 11: BDD with Spock](https://reader034.vdocuments.mx/reader034/viewer/2022050723/55a697371a28ab752d8b46ec/html5/thumbnails/11.jpg)
start2
명세작성
Class MyFirstSpecification extends Specification{
fields
fixture methods
feature methods
helper methods
}
![Page 12: BDD with Spock](https://reader034.vdocuments.mx/reader034/viewer/2022050723/55a697371a28ab752d8b46ec/html5/thumbnails/12.jpg)
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]
• }
시나리오시작
예상하는결과
![Page 13: BDD with Spock](https://reader034.vdocuments.mx/reader034/viewer/2022050723/55a697371a28ab752d8b46ec/html5/thumbnails/13.jpg)
Spock의 where절
• Given
• When,
• Then
• 표준템플릿유형이고반드시이유형으로작성해야하는것은아님
![Page 14: BDD with Spock](https://reader034.vdocuments.mx/reader034/viewer/2022050723/55a697371a28ab752d8b46ec/html5/thumbnails/14.jpg)
Spock의 where절의유형
• Spock의 where절은 2가지경우에사용
순회해야할요소를가지고있거나,
시나리오안에데이터테이블을가지고있을때
![Page 15: BDD with Spock](https://reader034.vdocuments.mx/reader034/viewer/2022050723/55a697371a28ab752d8b46ec/html5/thumbnails/15.jpg)
Spock where usage
where:
name <<["kirk",
"spock", "scotty"]
length <<[4, 5, 7]
where:
Name | gender
‘sara’ | ‘W’
‘mike’ | ‘m’
‘stacy’ | ‘w’
Namelength =name.length()
![Page 16: BDD with Spock](https://reader034.vdocuments.mx/reader034/viewer/2022050723/55a697371a28ab752d8b46ec/html5/thumbnails/16.jpg)
Reference
• https://github.com/spockframework/spock-example