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
69
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
610
Spockで学ぶテスト駆動開発のコツ
yonetty
1
950
『アジャイルソフトウェア開発の奥義』から学ぶテスト駆動開発
yonetty
0
360
Other Decks in Technology
See All in Technology
10XにおけるData Contractの導入について: Data Contract事例共有会
10xinc
6
660
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
160
組織成長を加速させるオンボーディングの取り組み
sudoakiy
2
210
いざ、BSC討伐の旅
nikinusu
2
780
TanStack Routerに移行するのかい しないのかい、どっちなんだい! / Are you going to migrate to TanStack Router or not? Which one is it?
kaminashi
0
600
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
プロダクト活用度で見えた真実 ホリゾンタルSaaSでの顧客解像度の高め方
tadaken3
0
180
安心してください、日本語使えますよ―Ubuntu日本語Remix提供休止に寄せて― 2024-11-17
nobutomurata
1
1k
日経電子版のStoreKit2フルリニューアル
shimastripe
1
140
データプロダクトの定義からはじめる、データコントラクト駆動なデータ基盤
chanyou0311
2
330
複雑なState管理からの脱却
sansantech
PRO
1
150
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
It's Worth the Effort
3n
183
27k
Become a Pro
speakerdeck
PRO
25
5k
GraphQLとの向き合い方2022年版
quramy
43
13k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Designing for Performance
lara
604
68k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
What's new in Ruby 2.0
geeforr
343
31k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Raft: Consensus for Rubyists
vanstee
136
6.6k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
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
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠