【Xcode】何も書いていないのにUITestが失敗する
この間、Xcodeでユニットテストを試そうと思ったら何も書いていないはずのUITestでエラーが起きて必ず「TestFailed」になる現象が起きた。
サードパーティのライブラリを導入しているプロジェクト限定で発生した。
あくまで今回の自分の場合ですが、対処方法をメモしておきます。
原因
Podfileの「UITest」部分に問題があった。
UITestでは画面描画が行われるので、画面描画に関わるライブラリはインストールされている必要があるらしい。何もテストを書いていないとしても。
自分の場合は「PopupDialog」というポップアップを表示するライブラリだった。
逆にSwiftLintやR.Swiftなど画面描画と関係ないものはPodfileのUITest部分に書く必要はないみたい。
追記
指摘を頂き気付きましたが上記は自分の勘違いだったようで、正しくはUITestでは別アプリから本体アプリを起動させているので、本体とは別にライブラリのインストールが要求される事は無いはずのようです。
実際の原因は、UITestのtargetに記述してある「inherit! :search_paths」が不要でした。
こちらのStackOverflowの記事に参考になりそうな事が書いてありました。
What does inherit! :search_paths do?
inherit! のオプション 「:complete(デフォルト)、:none、:search_paths」がそれぞれどういうものか理解しておく必要がありそうです。
対処方法
Before
target 'omikuji' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for omikuji
pod 'PopupDialog', '~> 1.1'
pod 'SwiftLint'
pod 'R.swift'
target 'omikujiTests' do
inherit! :search_paths
# Pods for testing
end
target 'omikujiUITests' do
inherit! :search_paths
# Pods for testing
end
end
After
target 'omikuji' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for omikuji
pod 'PopupDialog', '~> 1.1'
pod 'SwiftLint'
pod 'R.swift'
target 'omikujiTests' do
inherit! :search_paths
# Pods for testing
end
target 'omikujiUITests' do
# inherit! :search_paths // 不要
# Pods for testing
end
end
Author And Source
この問題について(【Xcode】何も書いていないのにUITestが失敗する), 我々は、より多くの情報をここで見つけました https://qiita.com/oimo23/items/92cc217639c50266a1e9著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .