LoginSignup
5
1

More than 5 years have passed since last update.

Bitrise 上でだけ指定したテストをスキップする方法

Posted at

Bitrise 上で動く時だけ、指定したテストをスキップさせる方法を紹介します。

Test 側の Info.plist に環境変数を追加

--- a/Example/Info.plist
+++ b/Example/Info.plist
@@ -4,6 +4,8 @@
 <dict>
        <key>CFBundleDevelopmentRegion</key>
        <string>en</string>
+       <key>Bitrise app title</key>
+       <string>$(BITRISE_APP_TITLE)</string>
        <key>CFBundleExecutable</key>
        <string>$(EXECUTABLE_NAME)</string>
        <key>CFBundleIdentifier</key>

テスト側に Bitrise 判定器を実装

BitriseDetector.swift
import Foundation



class BitriseDetector {
    static func isBitrise() -> Bool {
        let testBundle = Bundle(for: BitriseDetector.self)
        guard let bitriseAppTitle = testBundle.object(forInfoDictionaryKey: "Bitrise app title") as? String else {
            return false
        }

        return bitriseAppTitle == "example" // 👈 Bitrise に登録したアプリ名を入れる
    }
}

Bitrise ならテストをスキップさせる

TestFlags.swift
enum TestFlags {
    static let shouldDisableNetworkTests = BitriseDetector.isBitrise()
}
ExampleTests.swift
import XCTest

class ExampleTests: XCTestCase {
    func testExample() {
        guard TestFlags.shouldDisableNetworkTests else { return }

        // ...
    }
}

お疲れ様でした。

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1