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
2
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
850
標準パッケージにおけるテストでの利用例から学ぶ testing / quick パッケージ/golang-testing-quick
yusukehosonuma
4
11k
Swift で ParameterizedTest をやってみた話/swift-parameterized-test
yusukehosonuma
4
2k
Property-based test beginning with SwiftCheck
yusukehosonuma
1
5.4k
XCTest(再)入門/reintroduction-to-xctest
yusukehosonuma
0
410
ソースコードから読み解く - 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
6.1k
Other Decks in Programming
See All in Programming
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
720
たのしいparse.y
ydah
3
120
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
170
あれやってみてー駆動から成長を加速させる / areyattemite-driven
nashiusagi
1
200
急成長期の品質とスピードを両立するフロントエンド技術基盤
soarteclab
0
930
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
Beyond ORM
77web
3
430
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
540
今からはじめるAndroidアプリ開発 2024 / DevFest 2024
star_zero
0
1k
talk-with-local-llm-with-web-streams-api
kbaba1001
0
180
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
120
Featured
See All Featured
A designer walks into a library…
pauljervisheath
204
24k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Six Lessons from altMBA
skipperchong
27
3.5k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Navigating Team Friction
lara
183
15k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
How to Ace a Technical Interview
jacobian
276
23k
The Invisible Side of Design
smashingmag
298
50k
GraphQLとの向き合い方2022年版
quramy
44
13k
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