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
3.9k
君は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.7k
AssemblyScriptでライブラリコードの高速化をしてみる
gfx
5
2.9k
実践TypeScriptトークバトル
gfx
1
1.1k
歴史的経緯の説明 as code
gfx
7
2.7k
Elasticsearchによる 全文検索の実装 in Rails
gfx
5
9.4k
すばらしきGraphQLのSEKAIへようこそ
gfx
20
9.2k
マルチテナント・ウェブアプリケーションの実践
gfx
14
9.4k
How to choose the ORM on Android
gfx
1
4.1k
How Do We Get Along With Static Types
gfx
5
3.3k
Other Decks in Technology
See All in Technology
100 名超が参加した日経グループ横断の競技型 AWS 学習イベント「Nikkei Group AWS GameDay」の紹介/mediajaws202411
nikkei_engineer_recruiting
1
150
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
200
Terraform CI/CD パイプラインにおける AWS CodeCommit の代替手段
hiyanger
1
210
AWS Media Services 最新サービスアップデート 2024
eijikominami
0
160
Making your applications cross-environment - OSCG 2024 NA
salaboy
0
120
Why does continuous profiling matter to developers? #appdevelopercon
salaboy
0
120
【Pycon mini 東海 2024】Google Colaboratoryで試すVLM
kazuhitotakahashi
2
390
Shopifyアプリ開発における Shopifyの機能活用
sonatard
4
230
マルチモーダル / AI Agent / LLMOps 3つの技術トレンドで理解するLLMの今後の展望
hirosatogamo
31
9.3k
OCI 運用監視サービス 概要
oracle4engineer
PRO
0
4.7k
Terraform Stacks入門 #HashiTalks
msato
0
340
【令和最新版】AWS Direct Connectと愉快なGWたちのおさらい
minorun365
PRO
5
680
Featured
See All Featured
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Why Our Code Smells
bkeepers
PRO
334
57k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Fireside Chat
paigeccino
33
3k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Code Review Best Practice
trishagee
64
17k
Typedesign – Prime Four
hannesfritz
40
2.4k
The Cost Of JavaScript in 2023
addyosmani
45
6.7k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.2k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
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 ਓபืूத