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

コードカバレッジを⾒つつユニットテストを書く

 コードカバレッジを⾒つつユニットテストを書く

Avatar for Tomoya Miwa

Tomoya Miwa

March 18, 2019
Tweet

More Decks by Tomoya Miwa

Other Decks in Programming

Transcript

  1. About me tomoya0x00 Twitter, GitHub, Qiita Android, Embedded system, BLE/BT,

    iOS DeNA Co., Ltd. Automotive Business Unit. 前回(Otemachi.apk #01)は⾵邪で登壇できなかった
  2. 既存コード fun hoge(x: Int): String { if (x >= 3)

    return "many" if (x == 2) return "two" if (x == 1) return "one" if (x == 0) return "zero" return "other" }
  3. テストコードを⾜す @Test fun hogeTest() { assert(hoge(3) == "many") assert(hoge(2) ==

    "two") assert(hoge(1) == "one") assert(hoge(0) == "zero") assert(hoge(-1) == "other") // ★追加テストコード }
  4. Kotlinっぽくしてみる fun hoge(x: Int): String = when { x >=

    3 -> "many" x == 2 -> "two" x == 1 -> "one" x == 0 -> "zero" else -> "other" }