将xctest依赖项添加到Xcode 7项目 [英] Add xctest dependency to Xcode 7 project
问题描述
创建了一个新的OS X库项目,删除了Objective-C存根,并添加了一个Swift文件(Empty.swift).在同一目录中,添加了一个单元测试(new-> Unit Test)EmptyTest.swift.生成的代码无法编译,因为此OS X库项目不知道如何解决对XCTest的依赖性.
Created a new OS X library project, deleted the Objective-C stubs and add a Swift file (Empty.swift). In the same directory, added a unit test (new->Unit Test), EmptyTest.swift. The code generated won't compile because this OS X library project doesn't know how to resolve the dependency to XCTest.
XCTest在此位置/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/XCTest
XCTest is at this location /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/XCTest
The solution for command line tools is here (How can I run XCTest for a swift application from the command line?). How to add the dependency using Xcode 7?
推荐答案
您可以通过新目标添加单元测试用例,而不必在同一目标中创建文件
You can add Unit test case via new target instead of creating file in the same target
File - New - Target - OS X -Test - OS X Unit Testing Bundle
当您创建新的单元测试包时,它会以XCTest作为依赖关系来创建新的单元测试swift文件. 当您运行此目标时,它不会显示XCTest的错误
When you create new unit testing bundle it creates new unit test swift file with XCTest as dependancy When you run this target it don't show the error of XCTest
更新:如果您希望在同一目标中使用它.
在构建设置中找到FRAMEWORK_SEARCH_PATHS
并在其中添加$(PLATFORM_DIR)/Developer/Library/Frameworks
之后,如果您构建了自己的应用程序,则将成功构建
Update : If you want it in the same target.
In the Build Settings find FRAMEWORK_SEARCH_PATHS
and add $(PLATFORM_DIR)/Developer/Library/Frameworks
in it
after that if you build your app will build successfully
这篇关于将xctest依赖项添加到Xcode 7项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!