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
KotlinTest で始める Property-based Testing/kotlint...
Search
Yusuke Hosonuma
August 24, 2019
Programming
1
1.4k
KotlinTest で始める Property-based Testing/kotlintest-property-based-testing
Kotlin Fest 2019
https://kotlin.connpass.com/event/129860/
Yusuke Hosonuma
August 24, 2019
Tweet
Share
More Decks by Yusuke Hosonuma
See All by Yusuke Hosonuma
Marzipan の正体は何だったのか そして SwiftUI の衝撃/wwdc19_marzipan_swiftui
yusukehosonuma
2
830
標準パッケージにおけるテストでの利用例から学ぶ testing / quick パッケージ/golang-testing-quick
yusukehosonuma
4
11k
Swift で ParameterizedTest をやってみた話/swift-parameterized-test
yusukehosonuma
4
1.9k
Property-based test beginning with SwiftCheck
yusukehosonuma
1
5.3k
XCTest(再)入門/reintroduction-to-xctest
yusukehosonuma
0
380
ソースコードから読み解く - Quick はどのように実装されているのか?/quick-code-reading
yusukehosonuma
7
11k
Swift 4.2 はどのような進化をしているのか/whats-new-swift42
yusukehosonuma
16
14k
HTTPモックライブラリ「Mockingjay」を使ってみた話/swift-mockingjay
yusukehosonuma
5
3.7k
SwiftにおけるMockライブラリの活用/swift-mock-library
yusukehosonuma
10
6k
Other Decks in Programming
See All in Programming
ポケモンで考えるコミュニケーション / Communication Lessons from Pokémon
mackey0225
4
140
全方位強化 Python 服務可觀測性:以 FastAPI 和 Grafana Stack 為例
blueswen
1
360
Remix × Cloudflare Pages × Sentry 奮闘記 / remix-pages-sentry
nkzn
1
370
自分だけの世界を創るクリエイティブコーディング / Creative Coding: Creating Your Own World
chobishiba
1
130
利用者視点で考える、イテレータとの上手な付き合い方
syumai
4
210
Интеграционное тестирование: как приручить хаос
mariyasaygina
0
480
色んなオートローダーを覗き見る #phpcon_okinawa
o0h
PRO
5
360
CSC509 Lecture 02
javiergs
PRO
0
160
Compose Multiplatform과 Ktor로 플랫폼의 경계를 넘어보자
kwakeuijin
0
210
Assembling the Future: crafting the missing pieces of the Ruby on Wasm puzzle
skryukov
0
120
5年分のツケを一気に払った話
soogie
3
1.1k
Iteratorでページネーションを実現する
sonatard
3
700
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
786
250k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
Facilitating Awesome Meetings
lara
49
6k
The Cult of Friendly URLs
andyhume
76
6k
Done Done
chrislema
181
16k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
26
1.9k
Speed Design
sergeychernyshev
22
460
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
41
9.2k
Embracing the Ebb and Flow
colly
83
4.4k
Scaling GitHub
holman
458
140k
Fireside Chat
paigeccino
32
2.9k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
38
2.1k
Transcript
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. KotlinTest Ͱ࢝ΊΔ Property-based
Testing Yusuke Hosonuma @DeNA Kotlin Fest 2019
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. Yusuke Hosonuma @DeNA
Swift / Haskell / Go Twitter @tobi462
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. SoftWare Engineer in
Test ςετࣗಈԽʢiOS / Android / Goʣ CI/CDɺςετٕज़ͷݚڀ
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ࣥච $PNNJOHTPPOʜ
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. Agenda • KotlinTest
ͬͯʁ • Property-based Testing ͬͯʁ • ͲΜͳͱ͖ʹ͑Δʁ • ·ͱΊ ͳΜͱͳ͘ཧղ͕ΰʔϧ
KotlinTest ͬͯʁ Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ·ͣ
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. KotlinTest
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. KotlinTest ଟ͘ͷػೳΛαϙʔτ͢Δ ςεςΟϯάϑϨʔϜϫʔΫ
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ςεςΟϯάελΠϧ String Spec
Behavior Spec Feature Spec #%%
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ϚονϟʔAPI ʴ
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ςʔϒϧۦಈςετ σʔλΛࣄલʹྻڍ
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ςʔϒϧۦಈςετ σʔλΛࣄલʹྻڍ ΘΓͱશ෦Γͳ
ςεςΟϯάϑϨʔϜϫʔΫ ͱ͍͏ҹ
Property-based Testing ͬͯʁ Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
͡Ό͋
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. Property-based Testing •
ςετσʔλΛϥϯμϜʹੜͤ͞ • ͕ؔຬͨ͢ੑ࣭ʢPropertyʣΛݕূ͢Δ
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. Property-based Testing •
ςετσʔλΛϥϯμϜʹੜͤ͞ • ͦͷ͕ؔຬͨ͢ੑ࣭ʢPropertyʣΛݕূ͢Δ ͳΔ΄ͲɺΘ͔ΒΜɻ ྫΛݟͯΈΔ
͠ࢉʢʴʣͷ ςετͰൺֱ Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
Example-based Testing Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ීஈͬͯΔ
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. 1 + 1
= 2 / 2 + 3 = 5 class AddSpec: StringSpec({ "add" { forall( row(1, 1, 2), row(2, 3, 5) ) { a, b, expected -> (a + b) shouldBe expected } } })
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. class AddSpec: StringSpec({
"add" { forall( row(1, 1, 2), row(2, 3, 5) ) { a, b, expected -> (a + b) shouldBe expected } } }) ೖྗͱظΛ༻ҙͯ͠ 1 + 1 = 2 / 2 + 3 = 5
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. class AddSpec: StringSpec({
"add" { forall( row(1, 1, 2), row(2, 3, 5) ) { a, b, expected -> (a + b) shouldBe expected } } }) ݁Ռͱظ͕Ұக͢Δ͔ʁ 1 + 1 = 2 / 2 + 3 = 5
Property-based Testing Copyright (C) DeNA Co.,Ltd. All Rights Reserved. Ͱʁ
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ੑ࣭Λߟ͑Δ a +
b = b + a ަ๏ଇΛຬͨ͢
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ੑ࣭Λߟ͑Δ a +
b = b + a ʁ ʁ ͲΜͳͰΓཱͭ
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. KotlinTestͰݕূ class AddProperty:
StringSpec({ "commutative" { assertAll { a: Int, b: Int -> (a + b) shouldBe (b + a) } } })
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. KotlinTestͰݕূ class AddProperty:
StringSpec({ “commutative" { assertAll { a: Int, b: Int -> (a + b) shouldBe (b + a) } } }) ͯ͢ͷ
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. KotlinTestͰݕূ class AddProperty:
StringSpec({ “commutative" { assertAll { a: Int, b: Int -> (a + b) shouldBe (b + a) } } }) औΓ͏ΔBͱCʹ͍ͭͯ
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. KotlinTestͰݕূ class AddProperty:
StringSpec({ "commutative" { assertAll { a: Int, b: Int -> (a + b) shouldBe (b + a) } } }) B CC BͰ͋Δ͜ͱ
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. KotlinTestͰݕূ class AddProperty:
StringSpec({ "commutative" { assertAll { a: Int, b: Int -> (a + b) shouldBe (b + a) } } }) B CC BͰ͋Δ͜ͱ ϥϯμϜͳೖྗʹରͯ͠ ຬͨ͞ΕΔ͖ੑ࣭Λݕূ ৗʹ
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. debug print ͯ͠ΈΔͱ
ཚͰ ճࢼߦ͞ΕͯΔ
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. debug print ͯ͠ΈΔͱ
ཚͰ ճࢼߦ͞ΕͯΔ ύε͠ͳ͍σʔλ͕ͳ͍͔ େྔͷཚͰ͋ͿΓग़͢ ͱߟ͑Δͱ͔Γ͍͢
ͲΜͳ࣌ʹ͑Δʁ Copyright (C) DeNA Co.,Ltd. All Rights Reserved. Ͱ
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ͍Ͳ͜Ζ 1. ཚΛར༻ͨ͠ΞϧΰϦζϜ
2. ରশੑͷ͋ΔΞϧΰϦζϜ 3. ߴ vs
ཚΛར༻ͨ͠ΞϧΰϦζϜ Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ໎࿏ੜ • ͲΜͳ໎࿏Ͱղ͚ͳ͍ͱཱ͠ͳ͍
• ʮඞͣղ͚Δʯͱ͍͏ੑ࣭Λݕূ͢Δ
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ໎࿏ੜ • ͲΜͳ໎࿏Ͱղ͚ͳ͍ͱཱ͠ͳ͍
• ٯʹݴ͑ղ͚ͳ͍ͱόά • ʮඞͣղ͚Δʯͱ͍͏ੑ࣭Λݕূ͢Δ ྫ͑ Monkey Runner ϥϯμϜͳΠϕϯτΛൃߦ͠ଓ͚ ʮམͪͳ͍ʯੑ࣭Λݕূ͢Δ "OESPJEͷ
ରশੑͷ͋ΔΞϧΰϦζϜ Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. Τϯίʔυ / σίʔυ
• ͲΜͳΛΤϯίʔυ → σίʔυ ͯ͠ • ඞͣʮݩͷʹΔʯͱ͍͏ੑ࣭Λݕূ
ߴ vs Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ߴ vs
• ߴͳίʔυ͍ʢ͚Ͳෳࡶʣ • ͳίʔυ໌നʢ͚Ͳ͍ʣ • ͲͪΒʮಉ݁͡ՌʹͳΔʯͱ͍͏ੑ࣭Λར༻ • લऀͷݕূʹޙऀΛར༻͢Δ
·ͱΊ Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ·ͱΊ • KotlinTest
ςεςΟϯάϑϨʔϜϫʔΫ • Property-based Testing αϙʔτ • ϥϯμϜͳೖྗΛݩʹੑ࣭Λݕূ • Example-based Λஔ͖͑ΔͷͰͳ͍
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ·ͱΊ • KotlinTest
DSL Λ׆༻ͨ͠ςετϥΠϒϥϦ • Property-based Testing αϙʔτ • ϥϯμϜͳೖྗΛݩʹੑ࣭Λݕূ • Example-based Λஔ͖͑ΔͷͰͳ͍ ͱ͖ͬͭͮΒ͍ߟ͑ํ͕ͩ ͓֮͑ͯ͘ͱڧྗͳΧʔυ ࠷ॳ
એ Copyright (C) DeNA Co.,Ltd. All Rights Reserved.
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ͲͳͨͰొஃ0,ʂ
Copyright (C) DeNA Co.,Ltd. All Rights Reserved. ͲͳͨͰొஃ0,ʂ DeNA ʹͯ
9/9ʢ݄ʣ 19:00 ʙ
Let’s try Property-based Testing Copyright (C) DeNA Co.,Ltd. All Rights
Reserved. XJUI,PUMJO5FTU