xcode 在终端使用模拟器进行 OCUnit 应用测试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6596741/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OCUnit Application Test with Simulator in terminal
提问by Mats Stijlaart
Is it possible to start an application test that runs in the simulator with a terminal command(s)?
是否可以使用终端命令启动在模拟器中运行的应用程序测试?
Thanks
谢谢
回答by tonklon
Yes, I got it to work. My solution is somehow rough and might not be suitable in every case.
是的,我让它工作了。我的解决方案有点粗糙,可能并不适用于所有情况。
Disclaimer:This solution requires to edit system files. It works for me, but may mess up XCode's unit testing stack, especially if you do not understand what you are doing.
免责声明:此解决方案需要编辑系统文件。它对我有用,但可能会弄乱 XCode 的单元测试堆栈,尤其是当您不了解自己在做什么时。
In /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Tools/RunPlatformUnitTests
replace
在/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Tools/RunPlatformUnitTests
替换
if [ "${TEST_HOST}" != "" ]; then
Warning ${LINENO} "Skipping tests; the iPhoneSimulator platform does not currently support application-hosted tests (TEST_HOST set)."
else
with
和
if [ "${TEST_HOST}" != "" ]; then
mkdir -p "${BUILT_PRODUCTS_DIR}/Documents"
mkdir -p "${BUILT_PRODUCTS_DIR}/Library/Caches"
mkdir -p "${BUILT_PRODUCTS_DIR}/Library/Preferences"
mkdir -p "${BUILT_PRODUCTS_DIR}/tmp"
export CFFIXED_USER_HOME="${BUILT_PRODUCTS_DIR}/"
RunTestsForApplication "${TEST_HOST}" "${TEST_BUNDLE_PATH}"
else
You may move the fixed user home to a different location, but I think you would need to move the .app and .octest bundles along.
您可以将固定用户的家移动到不同的位置,但我认为您需要将 .app 和 .octest 包一起移动。
Add -RegisterForSystemEvents
to the OTHER_TEST_FLAGS
build setting of your test bundle.
添加-RegisterForSystemEvents
到OTHER_TEST_FLAGS
测试包的构建设置中。
Make sure your test bundle contains a run script build phase with the contents
确保您的测试包包含一个包含内容的运行脚本构建阶段
# Run the unit tests in this test bundle.
"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
Create a new scheme for your tests.
为您的测试创建一个新方案。
You should be able to run the tests from the command line using the standard xcodebuild:
您应该能够使用标准的 xcodebuild 从命令行运行测试:
xcodebuild -workspace $(WORKSPACE_NAME).xcworkspace -scheme $(TEST_SCHEME) -configuration debug -sdk iphonesimulator
xcodebuild -workspace $(WORKSPACE_NAME).xcworkspace -scheme $(TEST_SCHEME) -configuration debug -sdk iphonesimulator
The simulator must not be running, at the time you what to run the tests.
模拟器一定不能运行,在你运行测试的时候。
I hope this information is complete, if something doesn't work as expected please ask.
我希望这些信息是完整的,如果有什么不能按预期工作,请询问。
回答by Scott Babcock
You can ensure that the Simulator isn't running with this:
您可以确保模拟器没有运行:
osascript -e 'tell app "iPhone Simulator" to quit'
osascript -e 'tell app "iPhone Simulator" to quit'
You can determine if the Simulator is active with this:
您可以通过以下方式确定模拟器是否处于活动状态:
sh -c 'ps -xaco command | grep "iPhone Simulator"'
sh -c 'ps -xaco command | grep "iPhone Simulator"'
回答by ff10
It seems that with Xcode 4.5GM, running application tests in the simulator is now supported.
似乎在 Xcode 4.5GM 中,现在支持在模拟器中运行应用程序测试。
回答by Sveinung Kval Bakken
Worked perfectly, thanks!
Automated testing is back in action on our Jenkins CI-server!
Just had to fix my TEST_HOST=${BUNDLE_LOADER}
. Do this if you get errors about "no such file" when running the tests.
完美运行,谢谢!自动化测试在我们的 Jenkins CI 服务器上重新投入使用!只需要修复我的TEST_HOST=${BUNDLE_LOADER}
. 如果在运行测试时遇到“没有此类文件”的错误,请执行此操作。