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
Content Security Policy入門 セキュリティ設定と 違反レポートのはじめ方 / Introduction to Content Security Policy Getting Started with Security Configuration and Violation Reporting
uskey512
1
520
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Amazon Qを使ってIaCを触ろう!
maruto
0
400
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
870
初めてDefinitelyTypedにPRを出した話
syumai
0
400
イベント駆動で成長して委員会
happymana
1
320
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
330
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
4
640
Realtime API 入門
riofujimon
0
150
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
120
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
Featured
See All Featured
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Designing for Performance
lara
604
68k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
4 Signs Your Business is Dying
shpigford
180
21k
It's Worth the Effort
3n
183
27k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Code Reviewing Like a Champion
maltzj
520
39k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
No one is an island. Learnings from fostering a developers community.
thoeni
19
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