問題描述
為了自動測試應用程序,我想從我的 Mac 上重復啟動一個帶有不同參數的 iOS 應用程序.為簡單起見,我們假設它需要一個文件作為 argc,我有 100 個需要測試的文件.理論上,我只想重現 xcode build & 的行為.運行 - 在設備上運行,而不是越獄;該應用程序與硬件密切相關,因此僅靠模擬器是不夠的.
in order to automate testing an application, I want to repeatedly launch an iOS app with different arguments to it's main function from my mac; for simplicity let's just say it takes a file as argc and I have 100 files that I need to test. In theory, all I'd want to reproduce is the behaviour of xcode build & run - on the device, not jailbroken; the app is closely tied to the hardware, so the simulator alone will not suffice.
有幾個頁面做了類似的事情,但沒有一個使用該設備,也沒有一個真正說明控制臺上命令行的實際外觀.
There are a couple of pages that do something similar, but none of them use the device, and none of them actually spell out how the command line on the console would actually look like.
1) http://blog.carbonfive.com/2011/04/06/running-xcode-4-unit-tests-from-the-command-line/
此頁面設置最終在模擬器中運行的單元測試;他接著說
this page sets up a unit test that eventually runs in the simulator; he goes on to say that
單元測試構建目標的運行腳本"構建階段只是運行 >${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
The "Run Script" build phase of a unit test build target just runs >"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
我檢查了,但 RunPlatformUnitTests 和 RunUnitTests 都不是從 Xcode 4 執行的(我重命名了腳本以確保).
I checked that, but neither RunPlatformUnitTests nor RunUnitTests is executed from Xcode 4 (I renamed the scripts to make sure).
2) http://longweekendmobile.com/2011/04/17/xcode4-running-application-tests-from-the-command-line-in-ios/
此頁面從 1) 左側開始,但僅針對模擬器構建,并未指定應用程序的實際啟動方式.它很好地描述了它是如何從命令行構建的.
this page picks up where 1) left but only builds for the simulator and doesn't specify how the app is actually launched. It describes well how it's build from command line though.
3) 調試從命令行構建的 iOS 應用
我在 Xcode 4 中看到的是構建階段,它在簽名和驗證應用程序時停止.接下來我看到的是在設備上運行的 gdb 調試器.但是,我不知道如何訪問調試服務器 - 我沒有越獄我的 iPhone,所以我無法訪問它上面的任何東西,既沒有調試服務器也沒有 IP 地址.
What I see in Xcode 4 is the build phase, which stops at signing and validating the application. The next thing I see is the gdb debugger that runs on the device. However, I don't know how to access debugserver - I didn't jailbrake my iPhone so I have no access to just about anything on it, neither debugserver nor the IP adress.
我可以驗證的是,gdb 是從 xcode4/platforms/iPhoneOS.platform 調用的,因此遠程調試器必須以某種方式將自身附加到某些東西...
What I can verify is that gdb is called from xcode4/platforms/iPhoneOS.platform so the remote debugger must attach itself to something, somehow ...
推薦答案
命令行遠程GDB(或者只是上傳到設備)可以用這個小工具,選擇最接近你需要的fork,原作者不會再支持一下:https://github.com/ghughes/fruitstrap
For command line remote GDB (or just upload to device) you can use this little tool, choose the fork closest to what you need, the original author will not support it anymore: https://github.com/ghughes/fruitstrap
您可能無法按原樣使用它(我不得不調整 gdb 參數以供使用),但這是一個好的開始.
You may not be able to use it as-is (I had to tweak the gdb parameters for my use) but its a good start.
您可以通過自動運行此腳本來進一步自動化操作
You can further automate things by automatically run this script
for i in $(system_profiler SPUSBDataType | grep "Serial Number: " | grep -Po "[A-Za-z0-9]{40,}$") ; do
echo "Installing on: $i"
#use fruitstrap with device $i
end
這將簡單地檢查所有 USB 端口并僅保留當前連接到 iOS 設備的端口并返回其 UDID.
this will simply check all USB port and keep only the ones that are currently connected to an iOS device and return its UDID.
從那里你應該能夠為你的應用使用幾個不同的參數來自動化測試.
From there you should be able to automate the testing with several different arguments for your app.
這篇關于從 Mac OS X 控制臺啟動 iOS 應用程序的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!