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
君はPower Assertを知っているか #potatotips
Search
FUJI Goro
May 15, 2014
Technology
5
4k
君はPower Assertを知っているか #potatotips
potatotips #7 2015/5/15 at DeNA
FUJI Goro
May 15, 2014
Tweet
Share
More Decks by FUJI Goro
See All by FUJI Goro
How to Boost Your Code with WebAssembly
gfx
2
2.8k
AssemblyScriptでライブラリコードの高速化をしてみる
gfx
5
3k
実践TypeScriptトークバトル
gfx
1
1.1k
歴史的経緯の説明 as code
gfx
7
2.7k
Elasticsearchによる 全文検索の実装 in Rails
gfx
6
9.4k
すばらしきGraphQLのSEKAIへようこそ
gfx
20
9.3k
マルチテナント・ウェブアプリケーションの実践
gfx
14
9.5k
How to choose the ORM on Android
gfx
1
4.2k
How Do We Get Along With Static Types
gfx
5
3.3k
Other Decks in Technology
See All in Technology
GoogleのAIエージェント論 Authors: Julia Wiesinger, Patrick Marlow and Vladimir Vuskovic
customercloud
PRO
0
200
CDKのコードレビューを楽にするパッケージcdk-mentorを作ってみた/cdk-mentor
tomoki10
0
210
2025年のARグラスの潮流
kotauchisunsun
0
870
PaaSの歴史と、 アプリケーションプラットフォームのこれから
jacopen
7
1.6k
今年一年で頑張ること / What I will do my best this year
pauli
1
230
KMP with Crashlytics
sansantech
PRO
0
260
My small contributions - Fujiwara Tech Conference 2025
ijin
0
1.5k
Building Scalable Backend Services with Firebase
wisdommatt
0
110
2025年に挑戦したいこと
molmolken
0
200
AWSマルチアカウント統制環境のすゝめ / 20250115 Mitsutoshi Matsuo
shift_evolve
0
120
メールヘッダーを見てみよう
hinono
0
130
ゼロからわかる!!AWSの構成図を書いてみようワークショップ 問題&解答解説 #デッカイギ #羽田デッカイギおつ
_mossann_t
0
1.6k
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.2k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
580
Testing 201, or: Great Expectations
jmmastey
41
7.2k
Building Your Own Lightsaber
phodgson
104
6.2k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.4k
How GitHub (no longer) Works
holman
312
140k
Optimising Largest Contentful Paint
csswizardry
33
3k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
Being A Developer After 40
akosma
89
590k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
500
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
4
190
Transcript
܅ Power Assert Λ͍ͬͯΔ͔ FUJI Goro (@__gfx__), a software engineer
in COOKPAD #potatotips 2014/5/15 at DeNA
FUJI Goro (@__gfx__) • software engineer @ COOKPAD Inc. •
Android / iOS ͚ڞ௨ϥΠϒϥϦͷઃܭɾ։ൃ
Assertions in Java // EXPR͕ࣦഊ͢Δͱ throw new AssertionError() Λ࣮ߦ͢Δ assert
foo == 42; ! // commentAssertionErrorͷҾͱͯ͠͞ΕΔ assert foo == 42 : “with message”; ! // assertແޮ͕࣌ࣜධՁ͞Εͳ͍ͷͰॏΊͷલఏ݅νΣοΫՄ assert checkParamsButSlow(foo);
Assertions in Android • AndroidͰJavaͷassertจ͕͑Δ • `assert getActivity() != null;`
• ͨͩ͠assertσϑΥϧτͰແޮ • `adb shell setprop debug.assert 1` Ͱ༗ޮԽ • …Ͱ͖Δ͜ͱ͋Δʢ࣮ػͩͱͰ͖ͳ͍ʁʣ
Assertionsͷ • εΠον͕ΞϓϦ͝ͱͰͳ͘͝ͱ • ͦͦޮ͔ͳ͔ͬͨΓ͢Δ͠ • ։ൃऀશһͰৗʹ༗ޮʹ͢Δͱ͍͏ͷ͍͠ • ࣦഊ࣌ͷใʹ͍͠ •
ৄࡉΛ͏ͨΊʹϒϨʔΫϙΠϯτΛࠐΜͰ σόοά͢Δඞཁ͕͋Δ
ͭΒ͍
ͱ͜ΖͰ Power Assert Λ͍ͬͯ·͔͢
Power Assert ͷػೳ • assertࣦഊ࣌ʹؔ͢ΔࣜͷΛදࣔ͢Δ def x = new File(“foo.groovy”)
assert x.absolutePath.contains("bar") // shows: Assertion failed: ! assert x.absolutePath.contains("bar") | | | | | false | /path/to/foo.groovy foo.groovy at foo.run(foo.groovy:4)
࣮ͷͨΊͷπʔϧνΣΠϯ • ࣮ߦલʹίʔυΛॻ͖͑Δඞཁ͕͋Δ • JavaScript൛ιʔείʔυΛॻ͖͑Δ • SpockίϯύΠϧޙͷASTΛॻ͖͑Δ • ASTʹରͯ͠ϝλϓϩάϥϛϯάͰ͖Δڥ ͕͋ΕOK
AndroidͰPower Assert͕ ͍͍ͨੈքઢʹߦ͖͍ͨ…
– OSSքͷ֨ݴ “ͩͬͨΒ͓લ͕Ε”
Γ·ͨ͠
Android Power Assert Plugin • assertจΛڧ੍తʹ༗ޮԽ • assertࣦഊ࣌ʹใΛՃ • ϦϦʔεϏϧυͰԿ͠ͳ͍
• ࣮ߦʹӨڹ΄ͱΜͲͳ͠ • APKͷαΠζ૿͑ͳ͍
ग़ྗྫ assert findViewById(R.id.never).isFocused();
σϑΥϧτͷྫ֎
assert findViewById(R.id.never).isFocused(); with default mode java.lang.NullPointerException: at MainActivity.onButton2Click(MainActivity.java:28) (…stacktrace͕ଓ͘…) !
// NOTE: // KitKat͔Β͏গ͠ใ͕૿͑ͯɺͳʹ͕nullͩͬͨͷ͔Θ͔Γ͘͢ͳ͍ͬͯΔ
Power Assert༗ޮͷͱ͖
assert findViewById(R.id.never).isFocused(); with power assert java.lang.NullPointerException: 26: void onButton2Click() {
27> assert findViewById(R.id.never).isFocused(); 27: } MainActivity.findViewById()=<null> at MainActivity.onButton2Click(MainActivity.java:28) (…stacktrace͕ଓ͘…)
͍ํ // The root build.gradle buildscript { dependencies { classpath
‘com.github.gfx:android-power-assert-plugin:0.10.+’ } } ! // in build.gradle of a module apply plugin: ‘android-power-assert’
͋ͱassertจΛ͏͚ͩ
Power Assert ೋͭͷଆ໘
ΞϓϦέʔγϣϯίʔυͰ͏ • ڥ͕ಛఆͷঢ়ଶͰ͋Δ͜ͱΛอূ͢Δ • ҾͷνΣοΫnullνΣοΫͳͲ • Android StudioͰNPEܯࠂΛ੩ΊΔͨΊ • ϦϦʔε൛Ͱassertจফ͑ΔͷͰɺ͋͘·Ͱ
ʮ։ൃऀ͕ਖ਼͍͠ίʔυΛॻ͍͍ͯΔ͜ͱΛอ ূ͢ΔʯͨΊʹ͏
ςετͰ͏ • ൚༻ςετϚονϟʔͱͯ͠͏ • JUnitͷassertEquals()ͷҾͷॱ൪Λߟ͑ͳ͘ ͯΑ͘ͳΔ • ࣜͷ్தܦաΛදࣔ͢ΔͷͰɺෳͷ assertXXX()Λ·ͱΊΒΕΔ •
assert obj.foo().bar().equals(“baz”)
How it works
JavassistʹΑΔόΠτίʔυૢ࡞ • $assertionsDisabledΛৗʹfalseʹ͢Δ • assertจʢ͕ίϯύΠϧ͞ΕͨόΠτίʔυʣ Λݟ͚ͭͨΒपลใΛूΊͯจࣈྻΛੜ ͢ΔίʔυΛૠೖ͢Δ • field access
/ method calltry-catchͰғΜͰ NPEΛΩϟονˍपลใΛ༩ͯ͠re-throw
՝ • Ճใ͕ଟ͗͢Δ • ͍·ϩʔΧϧมΛͯ͢dump͍ͯ͠Δ • SpockͷΑ͏ͳࠩදࣔΛ͍ͨ͠ • ͍·commonsͷToStringBuilderΛ͍ͬͯΔ •
JavassistͰେྔͷίʔυΛॻ͘ͷਏ͍ͷͰɺग़ྗ ϑΥʔϚολΛผʹ࣮͢Δඞཁ͕͋Δ
We are hiring! https://info.cookpad.com/jobs/
͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ https://github.com/gfx/android-power-assert-plugin ਓபืूத