Upgrade to Pro — share decks privately, control downloads, hide ads and more …

君はPower Assertを知っているか #potatotips

君はPower Assertを知っているか #potatotips

potatotips #7 2015/5/15 at DeNA

FUJI Goro

May 15, 2014
Tweet

More Decks by FUJI Goro

Other Decks in Technology

Transcript

  1. FUJI Goro (@__gfx__) • software engineer @ COOKPAD Inc. •

    Android / iOS ޲͚ڞ௨ϥΠϒϥϦͷઃܭɾ։ൃ
  2. Assertions in Java // EXPR͕ࣦഊ͢Δͱ throw new AssertionError() Λ࣮ߦ͢Δ assert

    foo == 42; ! // comment͸AssertionErrorͷҾ਺ͱͯ͠౉͞ΕΔ assert foo == 42 : “with message”; ! // assertແޮ࣌͸͕ࣜධՁ͞Εͳ͍ͷͰॏΊͷલఏ৚݅νΣοΫ΋Մ assert checkParamsButSlow(foo);
  3. Assertions in Android • AndroidͰ͸Javaͷassertจ͕࢖͑Δ • `assert getActivity() != null;`

    • ͨͩ͠assert͸σϑΥϧτͰແޮ • `adb shell setprop debug.assert 1` Ͱ༗ޮԽ • …Ͱ͖Δ͜ͱ΋͋Δʢ࣮ػͩͱͰ͖ͳ͍ʁʣ
  4. 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)
  5. 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͕ଓ͘…)
  6. ࢖͍ํ // 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’