使用iOS实施单元测试 [英] Implementing Unit Testing with iOS

查看:104
本文介绍了使用iOS实施单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了

I've followed this tutorial to setup unit testing on my app when I got a little stuck.

在该教程的第8点,它显示了此图像,这是我在构建时应期望的图像:

At bullet point 8 in that tutorial it shows this image, which is what I should be expecting when I build: alt text http://developer.apple.com/library/ios/documentation/Xcode/Conceptual/iphone_development/art/logic_test_failure_text_editor.jpg

但是,这不是我构建时得到的.我收到以下错误消息:Command /bin/sh failed with exit code 1以及单元测试已创建的错误消息.然后,当我扩展第一个错误时,我得到了:

However this isn't what I get when I build. I get this error message: Command /bin/sh failed with exit code 1 as well as the error message the unit test has created. Then, when I expand on the first error I get this:

PhaseScriptExecution "Run Script" "build/3D Pool.build/Debug-iphonesimulator/LogicTests.build/Script-1A6BA6AE10F28F40008AC2A8.sh"
cd "/Users/james/Desktop/FYP/3D Pool"
setenv ACTION build
setenv ALTERNATE_GROUP staff
...
setenv XCODE_VERSION_MAJOR 0300
setenv XCODE_VERSION_MINOR 0320
setenv YACC /Developer/usr/bin/yacc
/bin/sh -c "\"/Users/james/Desktop/FYP/3D Pool/build/3D Pool.build/Debug-iphonesimulator/LogicTests.build/Script-1A6BA6AE10F28F40008AC2A8.sh\""

/Developer/Tools/RunPlatformUnitTests.include:412: note: Started tests for architectures 'i386'
/Developer/Tools/RunPlatformUnitTests.include:419: note: Running tests for architecture 'i386' (GC OFF)
objc[12589]: GC: forcing GC OFF because OBJC_DISABLE_GC is set
Test Suite '/Users/james/Desktop/FYP/3D Pool/build/Debug-iphonesimulator/LogicTests.octest(Tests)' started at 2010-01-04 21:05:06 +0000
Test Suite 'LogicTests' started at 2010-01-04 21:05:06 +0000
Test Case '-[LogicTests testFail]' started.
/Users/james/Desktop/FYP/3D Pool/LogicTests.m:17: error: -[LogicTests testFail] : Must fail to succeed.
Test Case '-[LogicTests testFail]' failed (0.000 seconds).
Test Suite 'LogicTests' finished at 2010-01-04 21:05:06 +0000.
Executed 1 test, with 1 failure (0 unexpected) in 0.000 (0.000) seconds

Test Suite '/Users/james/Desktop/FYP/3D Pool/build/Debug-iphonesimulator/LogicTests.octest(Tests)' finished at 2010-01-04 21:05:06 +0000.
Executed 1 test, with 1 failure (0 unexpected) in 0.000 (0.002) seconds

/Developer/Tools/RunPlatformUnitTests.include:448: error: Failed tests for architecture 'i386' (GC OFF)
/Developer/Tools/RunPlatformUnitTests.include:462: note: Completed tests for architectures 'i386'
Command /bin/sh failed with exit code 1

现在这很奇怪,因为它正在运行测试(并且可以成功看到STFail触发),因为如果我添加通过的其他测试,则不会出错,因此测试工作正常.但是为什么我的额外构建失败了?

Now this is very odd as it is running the tests (and succeeding as you can see my STFail firing) because if I add a different test which passes I get no errors, so the tests are working fine. But why am I getting this extra build fail?

还可能需要注意的是,当下载解决方案/模板时,我会得到相同的错误.我猜我在这里设置了错误,但是我只是正确地遵循了100%的教程!

It may also be of note that when downloading solutions/templates which should work out the box, I get the same error. I'm guessing I've set something up wrong here but I've just followed a tutorial 100% correctly!

根据此博客这篇文章和其他一些网站,不是唯一一个遇到此问题的人.自从xCode 3.2发行以来,情况一直是这样,假设apple dev center文档和教程等也是3.2之前的版本.

According to this blog, this post and a few other websites, I'm not the only one getting this problem. It has been like this since the release of xCode 3.2, assuming the apple dev center documents and tutorials etc are pre-3.2 as well.

但是,有些人说这是一个已知问题,而其他人似乎认为这是故意的.我一个人想要扩展控制台和代码消息,我当然不喜欢"Command/bin/sh ..."错误,并且真的认为他们会记录这样的更新.希望它将很快得到修复.

However some say its a known issue whereas others seem to think this was intentional. I for one would like both the extended console and in code messages, and I certainly do not like the "Command /bin/sh..." error and really think they would have documented such an update. Hopefully it will be fixed soon anyway.

更新: 确认自xCode 3.2.1发行以来,情况有所改变.

UPDATE: Here's confirmation it's something changed since the release of xCode 3.2.1.

此图片: 替代文字http://ing0.co.uk/info/pics/unittest-xcode-3.2.1.png 来自我使用3.2.1的测试版本.此版本来自旧版本(3.1.4): 替代文字http://ing0.co.uk/info/pics/unittest-xcode-3.1.4.png . (两者的项目均未更改).

This image: alt text http://ing0.co.uk/info/pics/unittest-xcode-3.2.1.png is from my test build using 3.2.1. This one is from an older version (3.1.4): alt text http://ing0.co.uk/info/pics/unittest-xcode-3.1.4.png. (The project for both was unchanged).

推荐答案

双击目标"/您的脚本目标名称"下的运行脚本",然后输入

Double click 'Run script' under 'Targets'/'Your script target name' then type


# Run the unit tests in this test bundle. 
"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests" 1> /tmp/RunUnitTests.out

基本上,您需要添加


1> /tmp/RunUnitTests.out

到已经存在的地方

这篇关于使用iOS实施单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆