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
Why App Signing Matters for Your Android Apps - Android Bangkok Conference 2024
akexorcist
0
120
[FOSS4G 2024 Japan LT] LLMを使ってGISデータ解析を自動化したい!
nssv
1
210
マルチモーダル / AI Agent / LLMOps 3つの技術トレンドで理解するLLMの今後の展望
hirosatogamo
37
12k
スクラムチームを立ち上げる〜チーム開発で得られたもの・得られなかったもの〜
ohnoeight
2
350
OCI Vault 概要
oracle4engineer
PRO
0
9.7k
Taming you application's environments
salaboy
0
180
TypeScriptの次なる大進化なるか!? 条件型を返り値とする関数の型推論
uhyo
2
1.6k
Adopting Jetpack Compose in Your Existing Project - GDG DevFest Bangkok 2024
akexorcist
0
100
個人でもIAM Identity Centerを使おう!(アクセス管理編)
ryder472
3
200
CysharpのOSS群から見るModern C#の現在地
neuecc
2
3.2k
Terraform CI/CD パイプラインにおける AWS CodeCommit の代替手段
hiyanger
1
240
OCI 運用監視サービス 概要
oracle4engineer
PRO
0
4.8k
Featured
See All Featured
Being A Developer After 40
akosma
86
590k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Thoughts on Productivity
jonyablonski
67
4.3k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Six Lessons from altMBA
skipperchong
27
3.5k
BBQ
matthewcrist
85
9.3k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
The Invisible Side of Design
smashingmag
298
50k
Automating Front-end Workflow
addyosmani
1366
200k
The Pragmatic Product Professional
lauravandoore
31
6.3k
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
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠