Xcode 5:单元测试未运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18948427/
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
Xcode 5: Unit Tests not running
提问by invalidArgument
I created a few test cases and they all passed... That's because they are not being run.
我创建了一些测试用例,它们都通过了……那是因为它们没有运行。
From Xcode, I get:
从 Xcode,我得到:
Test Suite 'All tests' started at... Test Suite 'All tests' finished at... Executed 0 tests, with 0 failures (0 unexpected) in 0.00 seconds
The project (and unit test classes) build successfully.
项目(和单元测试类)成功构建。
All my test classes have MyApp_appTests as Target Membership selected. Production classes have MyApp_app & MyApp_appTests targets selected.
我所有的测试类都选择了 MyApp_appTests 作为目标成员。生产类选择了 MyApp_app 和 MyApp_appTests 目标。
I verified the MyApp_appTests Target Build Settings (Bundle Loader & Test Host).
我验证了 MyApp_appTests 目标构建设置(Bundle Loader & Test Host)。
Bundle Loader (Debug): $(BUILT_PRODUCTS_DIR)/MyApp.app/MyApp
Test Host (Debug): $(BUNDLE_LOADER)
I have imported SenTestingKit.framework (through Targets Build Phases "Link Binary With Libraries").
我已经导入了 SenTestingKit.framework(通过 Targets Build Phases“Link Binary With Libraries”)。
All my tests start with -(void)testThat...
我所有的测试都以 -(void)testThat...
I have also checked a few stackoverflow.com questions:
我还检查了一些 stackoverflow.com 的问题:
stackoverflow.com/questions/8632254/xcode-4-2-cant-run-unit-teststackoverflow.com/questions/3608484/ocunit-tests-not-running-not-being-foundstackoverflow.com/questions/16672616/ocunit-test-cases-not-running
stackoverflow.com/questions/8632254/xcode-4-2-cant-run-unit-test stackoverflow.com/questions/3608484/ocunit-tests-not-running-not-being-found stackoverflow.com/questions/16672616/ ocunit 测试用例未运行
and this post:
和这篇文章:
twobitlabs.com/2011/06/adding-ocunit-to-an-existing-ios-project-with-xcode-4/
twobitlabs.com/2011/06/adding-ocunit-to-an-existing-ios-project-with-xcode-4/
I don't know where to look for... Any help is greatly appreciated!
我不知道在哪里寻找......非常感谢任何帮助!
采纳答案by zaph
Xcode 5 now used XCTestCase, not SenTest. Apple is now supporting Unit Testing more directly including their own version of SenTest named XCTestCase. Additionally the UI is much improved, allowing individual tests to be run, a Test Navigator and no longer creating .h test files. Note that the test macros are not renames with an XC prefix.
Xcode 5 现在使用 XCTestCase,而不是 SenTest。Apple 现在更直接地支持单元测试,包括他们自己的名为 XCTestCase 的 SenTest 版本。此外,UI 有了很大改进,允许运行单独的测试、测试导航器,并且不再创建 .h 测试文件。请注意,测试宏不会使用 XC 前缀进行重命名。
See the WWDC-13 video 409: "Testing in Xcode 5".
请参阅 WWDC-13 视频 409:“在 Xcode 5 中测试”。
If you use the Xcode 5 template to create the testing environment the project will include a test target and a working (and failing) test.
如果您使用 Xcode 5 模板创建测试环境,该项目将包括一个测试目标和一个工作(和失败)的测试。
回答by kraag22
For me worked changing "Wrapper extension" from "octest" to "xctest" in Build Settings for tests target
对我来说,在测试目标的构建设置中将“包装扩展”从“octest”更改为“xctest”
回答by Lucien
Try this:
尝试这个:
- Clean Project Derived Data
- Product > Clean
- Run the app
- Wait for Xcode indexing to finish
- 清理项目派生数据
- 产品 > 清洁
- 运行应用程序
- 等待 Xcode 索引完成
By this point the tests should reappear on the Test Navigator pane
此时,测试应重新出现在“测试导航器”窗格中
回答by jarora
I had this problem with Xcode 7.3, what worked for me was running the application on the device once and then running the tests.
我在 Xcode 7.3 上遇到了这个问题,对我有用的是在设备上运行应用程序一次然后运行测试。
回答by ram
If you are creating a new test target in Xcode 5+ and planning to use SenTestKit for unit tests, changing the 'Wrapper Extension' build setting of your test target to 'octest' from the default 'xctest' will help execute the test cases.
如果您正在 Xcode 5+ 中创建新的测试目标并计划使用 SenTestKit 进行单元测试,将测试目标的“Wrapper Extension”构建设置从默认的“xctest”更改为“octest”将有助于执行测试用例。