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
840
標準パッケージにおけるテストでの利用例から学ぶ 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
400
ソースコードから読み解く - 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
Jakarta EE meets AI
ivargrimstad
0
650
最新TCAキャッチアップ
0si43
0
190
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
2k
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
330
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
690
Quine, Polyglot, 良いコード
qnighy
4
640
EMになってからチームの成果を最大化するために取り組んだこと/ Maximize team performance as EM
nashiusagi
0
100
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
Realtime API 入門
riofujimon
0
150
Featured
See All Featured
Teambox: Starting and Learning
jrom
133
8.8k
Side Projects
sachag
452
42k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
10 Git Anti Patterns You Should be Aware of
lemiorhan
655
59k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
KATA
mclloyd
29
14k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
A better future with KSS
kneath
238
17k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Visualization
eitanlees
145
15k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
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