wantedly / ios_night

Let's talk about iOS development -- iOS Night 📱🌙 You might apply to this meetup from
https://www.wantedly.com/companies/wantedly/projects
18 stars 0 forks source link

2019/12/03 19:30~20:30 #77

Closed ShotaKashihara closed 4 years ago

ShotaKashihara commented 4 years ago

⚠️ This repository is public. / 公開リポジトリです。

Why

Where

Pearl Jam (Subject to change)

5F, MG Shirokanedai Building (Wantedly, Inc. Tokyo HQ)

Who

You are working for Wantedly? Sure, you can join anytime. If not, you need to contact us first. Or, you can "want to visit" the meetup, which you can find in www.wantedly.com/companies/wantedly/projects.

What

You write topics like below contents and we talk about these on the meetup. Every participant needs to write one topic at least.

Also, you can find new topics from the newsletters:

How

         ・・・

参加者は開催までに話したいことを少なくとも1トピックをコメントしましょう。 ネタ被りを避けるために、まずはタイトルだけでコメントすることを推奨します。 より多くの学びを得るためにどんな内容でもアウトプットを歓迎します!😊

cc/ @wantedly/ios

Edit this template

Previous issue

https://github.com/wantedly/ios_night/issues/76

ShotaKashihara commented 4 years ago

Firebase App Distribution 導入したよ

https://github.com/wantedly/yashima-ios/pull/6585/files

全部で3ステップ


  1. Gemfileに2行追加
plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
eval_gemfile(plugins_path) if File.exist?(plugins_path)
bundle install
  1. Firebase CLI をインストール

    npm install firebase-tools
  2. Fastfile に step を追加

    firebase_app_distribution(
    app: <<firebase_app_id>>,
    groups: "wantedly-1,developers-1",
    release_notes: "branch: #{git_branch}.\ncommit: #{last_git_commit[:message]}",
    firebase_cli_path: "./node_modules/.bin/firebase"
    )

出来上がり!

image

uhooi commented 4 years ago

突然ですが、明日お邪魔させていただくことになりました。 よろしくお願いします。

もしWatendlyさんで「パラメタライズドテスト(テーブル駆動テスト)」についてトピックを取り上げたことがなかったら、他社の勉強会の使い回しで恐縮ですが、以下について発表させていただきたいです。 https://gist.github.com/uhooi/6715b32d8e936e122816e2d069a0356c

一部を転記します。


パラメタライズドテストのメリット解説

メソッドをテストする

テストケースは何パターン必要?

func canWork(motivation: Int, hasRedBull: Bool) -> Bool {
    if motivation < 100 {
        return false
    }

    if !hasRedBull {
        return false
    }

    return true
}

正解は4パターン

motivation hasRedBull return value
99 true false
99 false false
100 true true
100 false false

手動でテストする

一覧表に○×を付けるのが一般的

No motivation hasRedBull return value 判定 日付 担当
1 99 true false OK 2019/11/29 ウホーイ
2 99 false false OK 2019/11/29 ウホーイ
3 100 true true NG 2019/11/29 ウホーイ
4 100 false false OK 2019/11/29 ウホーイ

自動でテストする

func test_canWork_motivation_99_hasRedBull_true() {
    let logic = LogicSample()
    XCTAssertFalse(logic.canWork(motivation: 99, hasRedBull: true))
}

func test_canWork_motivation_99_hasRedBull_false() {
    let logic = LogicSample()
    XCTAssertFalse(logic.canWork(motivation: 99, hasRedBull: false))
}

func test_canWork_motivation_100_hasRedBull_true() {
    let logic = LogicSample()
    XCTAssertTrue(logic.canWork(motivation: 100, hasRedBull: true))
}

func test_canWork_motivation_100_hasRedBull_false() {
    let logic = LogicSample()
    XCTAssertFalse(logic.canWork(motivation: 100, hasRedBull: false))
}

何も工夫していないテストコード

テストコードがわかりづらい、読みづらいと…

保守されなくなる

エクセルっぽく書きたい

motivation hasRedBull return value
99 true false
99 false false
100 true true
100 false false

エクセルっぽく書きたい

let tests: [(motivation: Int, hasRedBull: Bool, expect: Bool)] = [
    ( 99, true,  false),
    ( 99, false, false),
    (100, true,  true ),
    (100, false, false)
]

引数の配列を作り、ループしてテストすればいいんだ!

自動でテストする(工夫)

func test_canWork() {
    let tests: [(line: UInt, motivation: Int, hasRedBull: Bool, expect: Bool)] = [
        (#line,  99, true,  false),
        (#line,  99, false, false),
        (#line, 100, true,  true ),
        (#line, 100, false, false)
    ]

    for (line, motivation, hasRedBull, expect) in tests {
        let logic = LogicSample()
        let result = logic.canWork(motivation: motivation, hasRedBull: hasRedBull)
        XCTAssertEqual(result, expect, line: line)
    }
}

わかりやすい!

パラメタライズドテスト(parameterized test)

このように、引数のみを切り替えて実行するテストを 「 パラメタライズドテスト 」という

言語によって呼び方が異なることがある

言語 名前
Go テーブル駆動テスト
Java パラメータ化テスト

他言語では一般的なのに、なぜかSwiftでは知られていない…

Swiftでの実装詳細

@tobi462さんの資料がとても参考になります

Swift で ParameterizedTest をやってみた話/swift-parameterized-test - Speaker Deck
https://speakerdeck.com/yusukehosonuma/swift-parameterized-test

おまけ

Swiftでも、SpockのData Tablesのように書きたい!

class MathSpec extends Specification {
  def "maximum of two numbers"(int a, int b, int c) {
    expect:
    Math.max(a, b) == c

    where:
    a | b | c
    1 | 3 | 3
    7 | 4 | 7
    0 | 0 | 0
  }
}

演算子のオーバーロードとFunction Buildersで実現できないかな…

参考
http://spockframework.org/spock/docs/1.3/data_driven_testing.html#data-tables

ご清聴ありがとうございました

サンプルコード
https://github.com/uhooi/yumemi-swift-5-sample

sorakoro commented 4 years ago

SwiftUIのプレビューについて

https://nshipster.com/swiftui-previews/

ngtk commented 4 years ago

Combine and SwiftUI views

https://swiftwithmajid.com/2019/11/27/combine-and-swiftui-views/

ngtk commented 4 years ago

Modern Networking in Swift 5 with URLSession, Combine and Codable

https://www.vadimbulavin.com/modern-networking-in-swift-5-with-urlsession-combine-framework-and-codable/

jiro commented 4 years ago

@uhooi このちょっとした工夫良いですね! 😄 https://github.com/uhooi/yumemi-swift-5-sample/commit/c19b4025f611278139400e71a70d6f27872d45aa

uhooi commented 4 years ago

@hedjirog ありがとうございます! この工夫自体は参考にさせていただいた資料とほとんど同じなのですが、あまり広まっていないようなので発表しようと思いました😌

ShotaKashihara commented 4 years ago

おつかれさまでした! 良い回だったと思います!

ngtk commented 4 years ago

良い会でしたね!