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
390
ソースコードから読み解く - 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
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
120
飲食業界向けマルチプロダクトを実現させる開発体制とリアルな現状
hiroya0601
1
390
Importmapを使ったJavaScriptの 読み込みとブラウザアドオンの影響
swamp09
4
1.2k
GCCのプラグインを作る / I Made a GCC Plugin
shouth
1
150
cXML という電子商取引の トランザクションを支える プロトコルと向きあっている話
phigasui
3
2.2k
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
410
開発効率向上のためのリファクタリングの一歩目の選択肢 ~コード分割~ / JJUG CCC 2024 Fall
ryounasso
0
360
OpenTelemetryでRailsのパフォーマンス分析を始めてみよう(KoR2024)
ymtdzzz
4
1.5k
PLoP 2024: The evolution of the microservice architecture pattern language
cer
PRO
0
1.4k
推し活の ハイトラフィックに立ち向かう Railsとアーキテクチャ - Kaigi on Rails 2024
falcon8823
6
2k
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
880
Universal Linksの実装方法と陥りがちな罠
kaitokudou
1
220
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
43
6.6k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Git: the NoSQL Database
bkeepers
PRO
425
64k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
A Modern Web Designer's Workflow
chriscoyier
692
190k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
We Have a Design System, Now What?
morganepeng
50
7.2k
Producing Creativity
orderedlist
PRO
341
39k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
GraphQLの誤解/rethinking-graphql
sonatard
66
9.9k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
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