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
サイバーエージェントにおける生成AIのリスキリング施策の取り組み / cyber-ai-reskilling
cyberagentdevelopers
PRO
2
200
大規模データ基盤チームのオンプレTiDB運用への挑戦 / dpu-tidb
cyberagentdevelopers
PRO
1
110
Shift-from-React-to-Vue
calm1205
3
1.3k
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
27
12k
CAMERA-Suite: 広告文生成のための評価スイート / ai-camera-suite
cyberagentdevelopers
PRO
3
270
フルカイテン株式会社 採用資料
fullkaiten
0
36k
ABEMA のコンテンツ制作を最適化!生成 AI x クラウド映像編集システム / abema-ai-editor
cyberagentdevelopers
PRO
1
180
プロダクト成長に対応するプラットフォーム戦略:Authleteによる共通認証基盤の移行事例 / Building an authentication platform using Authlete and AWS
kakehashi
1
150
Apple/Google/Amazonの決済システムの違いを踏まえた定期購読課金システムの構築 / abema-billing-system
cyberagentdevelopers
PRO
1
220
一休.comレストランにおけるRustの活用
kymmt90
3
580
AWS CodePipelineでコンテナアプリをデプロイした際に、古いイメージを自動で削除する
smt7174
1
100
「 SharePoint 難しい」ってよく聞くけど、そんなに言うなら8歳の息子に試してもらった
taichinakamura
1
630
Featured
See All Featured
A Tale of Four Properties
chriscoyier
156
23k
A Philosophy of Restraint
colly
203
16k
Practical Orchestrator
shlominoach
186
10k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Scaling GitHub
holman
458
140k
Being A Developer After 40
akosma
86
590k
The Invisible Side of Design
smashingmag
297
50k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.2k
Git: the NoSQL Database
bkeepers
PRO
425
64k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
328
21k
Art, The Web, and Tiny UX
lynnandtonic
296
20k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
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
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠