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
68
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
590
Spockで学ぶテスト駆動開発のコツ
yonetty
1
940
『アジャイルソフトウェア開発の奥義』から学ぶテスト駆動開発
yonetty
0
350
Other Decks in Technology
See All in Technology
「視座」の上げ方が成人発達理論にわかりやすくまとまってた / think_ perspective_hidden_dimensions
shuzon
2
4.1k
GitHub Universe: Evaluating RAG apps in GitHub Actions
pamelafox
0
180
Jr. Championsになって、強く連携しながらAWSをもっと使いたい!~AWSに対する期待と行動~
amixedcolor
0
190
小規模に始めるデータメッシュとデータガバナンスの実践
kimujun
3
590
ガチ勢によるPipeCD運用大全〜滑らかなCI/CDを添えて〜 / ai-pipecd-encyclopedia
cyberagentdevelopers
PRO
3
210
AIを駆使したゲーム開発戦略: 新設AI組織の取り組み / sge-ai-strategy
cyberagentdevelopers
PRO
1
130
チームを主語にしてみる / Making "Team" the Subject
ar_tama
4
310
【若手エンジニア応援LT会】AWS Security Hubの活用に苦労した話
kazushi_ohata
0
170
MAMを軸とした動画ハンドリングにおけるAI活用前提の整備と次世代ビジョン / abema-ai-mam
cyberagentdevelopers
PRO
1
110
分布で見る効果検証入門 / ai-distributional-effect
cyberagentdevelopers
PRO
4
700
「 SharePoint 難しい」ってよく聞くけど、そんなに言うなら8歳の息子に試してもらった
taichinakamura
1
620
物価高なラスベガスでの過ごし方
zakky
0
380
Featured
See All Featured
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
GitHub's CSS Performance
jonrohan
1030
460k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Done Done
chrislema
181
16k
Product Roadmaps are Hard
iamctodd
PRO
48
10k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Designing on Purpose - Digital PM Summit 2013
jponch
115
6.9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
Designing the Hi-DPI Web
ddemaree
280
34k
Speed Design
sergeychernyshev
24
570
Practical Orchestrator
shlominoach
186
10k
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
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠