[iOS] デタラメな操作で自動テストしてくれる「CrashMonkey」

iOS アプリで、デタラメな操作で自動テストしてくれる「CrashMonkey」が便利だったのでご紹介します。

GitHub: mokemokechicken/CrashMonkey

CrashMonkeyのインストール

crash_monkey gem をインストールします。

% gem install crash_monkey

CrashMonkey の実行方法

簡単には crash_monkey コマンドでアプリのファイル名を指定すれば iOS シミュレータでテストが自動実行されます。

% crash_monkey -a MyApp.app

他のオプションは、githubでご確認下さい。

CrashMonkeyがエラーで実行できないときの解決方法

最初、CrashMonkeyが下記のようなエラーで実行できませんでした。

% crash_monkey -a MyApp.app
{:app_path=>"MyApp.app", :run_count=>2, :time_limit_sec=>100}
=================================== Start Test (1/2) =======================================
2 apps are found, USE NEWEST APP: /Users/your_username/Library/Developer/Xcode/DerivedData/MyApp-dmjxyavvpzcngmeyaoznanghixim/Build/Products/Debug-iphonesimulator/MyApp.app
ls: /Users/your_username/Library/Logs/DiagnosticReports/MyApp_*.crash: No such file or directory
Run: ["instruments", "-l", "100000", "-t", "/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate", "/Users/your_username/Library/Developer/Xcode/DerivedData/MyApp-dmjxyavvpzcngmeyaoznanghixim/Build/Products/Debug-iphonesimulator/MyApp.app", "-e", "UIASCRIPT", "/Users/your_username/git/myapp-ios/crash_monkey_result/UIAutoMonkey.js", "-e", "UIARESULTSPATH", "/Users/your_username/git/myapp-ios/crash_monkey_result"]
xcode-select: Error: No Xcode folder is set. Run xcode-select -switch <xcode_folder_path> to set the path to the Xcode folder.
Error: /usr/bin/xcode-select returned unexpected error.
tail finished: system.log
ls: /Users/your_username/Library/Logs/DiagnosticReports/MyApp_*.crash: No such file or directory
No matching processes belonging to you were found
=================================== Start Test (2/2) =======================================
ls: /Users/your_username/Library/Logs/DiagnosticReports/MyApp_*.crash: No such file or directory
Run: ["instruments", "-l", "100000", "-t", "/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate", "/Users/your_username/Library/Developer/Xcode/DerivedData/MyApp-dmjxyavvpzcngmeyaoznanghixim/Build/Products/Debug-iphonesimulator/MyApp.app", "-e", "UIASCRIPT", "/Users/your_username/git/myapp-ios/crash_monkey_result/UIAutoMonkey.js", "-e", "UIARESULTSPATH", "/Users/your_username/git/myapp-ios/crash_monkey_result"]
xcode-select: Error: No Xcode folder is set. Run xcode-select -switch <xcode_folder_path> to set the path to the Xcode folder.
Error: /usr/bin/xcode-select returned unexpected error.
tail finished: system.log
ls: /Users/your_username/Library/Logs/DiagnosticReports/MyApp_*.crash: No such file or directory
No matching processes belonging to you were found
EXIT 0

xcode-select コマンドで、Xcode の正しいインストールパスを指定すれば正常に動作したので、同じようなエラーが出た方は下記のコマンドを実行してみて下さい。

% sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

まとめ

自動でテストできるので、リリース前に何回か CrashMonkey 実行して確認しておくと良いかなと思いました。

参考情報