0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

XCTest を使った iOS アプリのテストについて

Posted at

XCTest

XCTest というフレームワークを利用することで、 iOS アプリの自動テストを簡単に実装することができます。

Reference: https://developer.apple.com/documentation/xctest

デバッグ

XCUIApplication.debugDescription function を利用することで、テスト対象のアプリの UI の要素、およびそれらの階層構造を知ることができます。
テストが期待通りに動かなかった際に、デバッグのために以下のようなコードをテストコードに挿入することがよくあります。

print(app.debugDescription)

Reference: https://developer.apple.com/documentation/xctest/xcuielement/1500909-debugdescription

特定の UI 要素の取得方法

SwiftUI において以下のように  NavigationLink が複数表示(entries に含まれる要素の数だけ NavigationLink が表示)される場合、

ForEach(entries, id:\.self) { entry in
    NavigationLink(destination: DetailView(entry: entry)) {
        CompactView(entry: entry)
    }
    .accessibility(identifier: "EntryNavigationLink")
}

テストコードにおいては以下のように identifier を利用することで要素の数(entries の数)を確認できる。

app.buttons.matching(identifier: "EntryNavigationLink").count
0
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?