Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
君はPower Assertを知っているか #potatotips
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
FUJI Goro
May 15, 2014
Technology
4.1k
5
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
君はPower Assertを知っているか #potatotips
potatotips #7 2015/5/15 at DeNA
FUJI Goro
May 15, 2014
More Decks by FUJI Goro
See All by FUJI Goro
ステートレスなLLMでステートフルなAI agentを作る - YAPC::Fukuoka 2025
gfx
7
2k
How to Boost Your Code with WebAssembly
gfx
2
3.2k
AssemblyScriptでライブラリコードの高速化をしてみる
gfx
5
3.4k
実践TypeScriptトークバトル
gfx
1
1.3k
歴史的経緯の説明 as code
gfx
7
2.9k
Elasticsearchによる 全文検索の実装 in Rails
gfx
6
9.8k
すばらしきGraphQLのSEKAIへようこそ
gfx
20
10k
マルチテナント・ウェブアプリケーションの実践
gfx
14
9.9k
How to choose the ORM on Android
gfx
1
4.5k
Other Decks in Technology
See All in Technology
AIに丸投げしないトイル削減 / Eliminating Toil Without Leaving It All to AI
kohbis
4
1.1k
Podは生きているのにGoだけが落ちる:GOGCとGOMEMLIMITで追うInvisible OOM Killの謎
tkc66buzz
1
610
あるけみー式LTスライド作成術
alchemy1115
1
200
GoにおけるFFIのこれまでとこれから
goccy
5
2.5k
Where Is JetBrains AI Heading- — Central CLI, Air Alpha, and the Agentic Development Stack
x5gtrn
PRO
0
160
作品が生態系になった ─ Mini Tokyo 3D から世界へ
nagix
0
170
#jawssonic2026 あの時代が悪かった ~動かなかったSageMakerと共に迎えたイベント当日~
ktkn1129
0
150
Omarchy Quattro の日本語設定周り
simosako
2
150
module Synths; end
asonas
1
130
AI時代に顧客へ最速で価値を 届けるための試行錯誤 〜「AI × マネジメント」領域におけるmentoのケース〜
posterkeisuke
0
110
新機種発売前に見直そう!端末移行で再ログインが要るアプリ・要らないアプリは何が違うのか 〜シームレスに再開できる設計と実装〜
zozotech
PRO
0
110
消えない 動かない 効かない
yama3133
1
120
Featured
See All Featured
Paper Plane (Part 1)
katiecoart
PRO
1
11k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
450
Mind Mapping
helmedeiros
1
350
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
690
Amusing Abliteration
ianozsvald
1
290
The SEO Collaboration Effect
kristinabergwall1
1
550
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
350
Crafting Experiences
bethany
1
320
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
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 ਓபืूத