Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Testing Java With Spock
Search
yonetty
December 25, 2019
Technology
0
70
Testing Java With Spock
Java Testing Challenge LT大会(第1回)でのLTネタ。
yonetty
December 25, 2019
Tweet
Share
More Decks by yonetty
See All by yonetty
技術書を読む技術(JJUG CCC 2023 Fall)
yonetty
3
680
Spockで学ぶテスト駆動開発のコツ
yonetty
1
960
『アジャイルソフトウェア開発の奥義』から学ぶテスト駆動開発
yonetty
0
370
Other Decks in Technology
See All in Technology
.NET 9 のパフォーマンス改善
nenonaninu
0
690
Amazon Kendra GenAI Index 登場でどう変わる? 評価から学ぶ最適なRAG構成
naoki_0531
0
100
Postman と API セキュリティ / Postman and API Security
yokawasa
0
200
開発生産性向上! 育成を「改善」と捉えるエンジニア育成戦略
shoota
1
230
オプトインカメラ:UWB測位を応用したオプトイン型のカメラ計測
matthewlujp
0
170
どちらを使う?GitHub or Azure DevOps Ver. 24H2
kkamegawa
0
670
成果を出しながら成長する、アウトプット駆動のキャッチアップ術 / Output-driven catch-up techniques to grow while producing results
aiandrox
0
180
プロダクト開発を加速させるためのQA文化の築き方 / How to build QA culture to accelerate product development
mii3king
1
260
re:Invent をおうちで楽しんでみた ~CloudWatch のオブザーバビリティ機能がスゴい!/ Enjoyed AWS re:Invent from Home and CloudWatch Observability Feature is Amazing!
yuj1osm
0
120
ハイテク休憩
sat
PRO
2
140
TSKaigi 2024 の登壇から広がったコミュニティ活動について
tsukuha
0
160
NW-JAWS #14 re:Invent 2024(予選落ち含)で 発表された推しアップデートについて
nagisa53
0
250
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Agile that works and the tools we love
rasmusluckow
328
21k
Visualization
eitanlees
146
15k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Become a Pro
speakerdeck
PRO
26
5k
Facilitating Awesome Meetings
lara
50
6.1k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Embracing the Ebb and Flow
colly
84
4.5k
Designing Experiences People Love
moore
138
23k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Statistics for Hackers
jakevdp
796
220k
Transcript
5FTUJOH+BWBXJUI4QPDL /PW +BWB5FTUJOH$IBMMFOHF-5 !UZPOFLVCP
"CPVU.F OBNFlถٱอ߶z UXJUUFSl!UZPOFLVCPz CMPHlIUUQTCMPHZOLCYZ[z XPSLGPSl4*FSz KPClύοέʔδιϑτͷ։ൃ5-z GBWPSJUFMBOHl4DBMBz
ϨΨγʔγεςϜ͋Δ͋Δ ςετ͠ʹ͍͘ ΞʔΩςΫνϟɾઃܭ ςετίʔυ͕গͳ͍ վम͢Δͷ͕ා͍ɺ ϦϑΝΫλϦϯά ༰қʹͰ͖ͳ͍ ύονϫʔΫతͳ ͦͷ͠ͷ͗ͷվम
5FTUBCJMJUZ ςετ͍͢͠ઃܭ Α͍ઃܭ cc
&/6' 5%%Α͍ઃܭʹಋ͕͘ɺ Α͍ΞʔΩςΫνϟ͕ࣗવʹ ੜ·ΕΔΘ͚Ͱͳ͍ ͋ΔఔͷΞʔΩςΫςΟϯά ඞཁ &/PVHIEFTJHO6Q'SPOU
$MFBO"SDIJUFDUVSFΛ࠾༻ w υϝΠϯʹϩδοΫΛू w ৄࡉ 8FC %*ίϯ %# FUD ͷґଘੑΛഉআ
υϝΠϯϦονͳΦϒδΣΫτ 10+0 ςετ͍͢͠ʂ ςετ͕͍ʂʂ
͍ͬͯΔςετπʔϧ FFςετ डೖςετ ຊ4QPDLʹ ͍ͭͯͷ͓ w $VDVNCFS4FSFOJUZΛͬͨ FFςετɺडೖςετ #%%
w 4QPDLΛͬͨϢχοτςετ 5%%
8IZ4QPDL +BWBͰίʔυΛॻ͘ͷ͕ͭΒ͍ʢʣ ɾεΫϦϓτݴޠͰ͋Δ(SPPWZͷखܰ͞ɾॊೈੑ ɾ4QPDLͷ%4-ʹΑΔςετίʔυͷՄಡੑ
4QPDLͷ͍͍ͱ͜Ζ ᶃ (SPPWZͰίʔυΛॻ͘ͷָ͕ ᶄ #%%ελΠϧ (JWFO8IFO5IFO ᶅ ڧྗͳΞαʔγϣϯ ᶆ
ύϥϝλϥΠζυɾςετ ᶇ ϞοΫϥΠϒϥϦෆཁ
(SPPWZͰίʔυΛॻ͘ͷָ͕ when: "ύʔςΟΛΉ" def party = Party.of(taro, hanako, ichiro) then:
"ϝϯόʔ͕ਖ਼͍͠" party.getNumberOfPeople() == 3 party.getPeople() == [taro, hanako, ichiro] มએݴʹܕͷ ࢦఆ͕ෆཁ EFG -JTU.BQͷ Ϧςϥϧදه ϓϦϛςΟϒܕΦϒδΣΫτ ܕͰൺֱ
#%%ελΠϧ (JWFO8IFO5IFO def "20ࡀେਓʹྨ͞ΕΔ"() { given: "ྸ20ࡀ" int age =
20 when: "ྉۚྨΛऔಘ" def feeClass = FeeClassification.of(age) then: "େਓ" feeClass == FeeClassification.Adults } HJWFO ࣄલ݅Λهड़ XIFO ςετରͷ ΞΫγϣϯΛهड़ UIFO ࣄޙ݅Λݕূ ୯ͳΔϒϩοΫׂ Ͱͳ͍ʂ w w w w
ڧྗͳΞαʔγϣϯ when: "ύʔςΟΛΉ" def party = Party.of(taro, hanako, ichiro) then:
"ϝϯόʔ͕ਖ਼͍͠" party.getNumberOfPeople() == 3 party.getPeople() == [taro, hanako, ichiro] Condition not satis ed: party.getPeople() == [taro, hanako, ichiro] | | | | | | | | | | (33) (8) | | | (35) | | false | [ (35), (8), (33)] <com.example.tjws.Party@ f a peopleList=[ (35), (8), (33)]> UIFOϒϩοΫʹΞαʔτ ͍ͨࣜ͠Λྻڍ͢Δ Ξαʔγϣϯʹࣦഊͨ͠ ߹ͷ֬ೝ͕༰қ
ύϥϝλϥΠζυɾςετ @Unroll def "ྸʹԠͯ͡ਖ਼͘͠ྨ͞ΕΔ #ageࡀ -> #expectedClass"() { when: "ྉۚྨΛऔಘ"
def feeClass = FeeClassification.of(age) then: "ྨ͕ਖ਼͍͠" feeClass == expectedClass where: age | expectedClass 0 | FeeClassification.Infants 3 | FeeClassification.Infants 4 | FeeClassification.Children 12 | FeeClassification.Children 13 | FeeClassification.Adults 64 | FeeClassification.Adults 65 | FeeClassification.SeniorCitezens } ڥքͷςετͳͲɺ݅Λ͍Ζ͍Ζ ม͑ͯςετΛߦ͍͍ͨ࣌ʹɺςετ έʔεΛ͚ΔͷͰ໘ ˣ XIFSFϒϩοΫʹදܗࣜͰهड़ͨ͠ ύϥϝʔλΛͬͯɺ܁Γฦ͠ςετ ͕࣮ߦ͞ΕΔ
ϞοΫϥΠϒϥϦෆཁ given: "ଠେਓ(20ࡀ)" def taro = new Person("ଠ", 20) and:
"ύʔςΟҰਓ" def party = Party.of(taro) and: "ྉۚදͷϞοΫ" def feeTable = Mock(FeeTable) and: "ྉۚܭࢉػ" def calculator = new FeeCalculator(feeTable) when: "ྉۚܭࢉΛߦ͏" def amount = calculator.calcTotalFee(party) then: "ྉۚද͕༻͞ΕΔ" 1 * feeTable.getFeeFor(FeeClassification.Adults) >> 1000 and: "ֹ͕ۚਖ਼͍͠" amount == 1000 ϞοΫελϒػೳ 4QPDLʹแ͞Ε͍ͯΔ ϞοΫͷৼΔ͍ͱظಈ࡞Λ UIFOϒϩοΫʹهड़Ͱ͖Δ ϝιου͕ݺΕΔఆճ O ͰදݱͰ͖Δ
·ͱΊ w 4QPDLΛ͏ͱςετΛॻ͘ͷָ͕ʂ w ͘͠ͳ͍ͷͰɺ+BWBͷ։ൃϓϩδΣΫ τʹಋೖ͕͍͢͠ʂ w 4QPDLͰָ͍͠5FTU-JGFΛʂ αϯϓϧίʔυ(JU)VCͰެ։ͯ͠·͢ https://github.com/yonetty/testing-java-with-spock
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠