XCTest / XCTest。没有在Xcode 6中构建的旧项目中找到。

时间:2022-04-18 20:39:57

I have a few projects I'm trying to build with Xcode 6 Beta 2. The projects all have some type of library that uses XCTest (Kiwi/XCTest and Specta) that don't build in Xcode 6 because XCTest/XCTest.h cannot be found.

我正在尝试用Xcode 6 Beta 2构建一些项目。这些项目都有某种类型的库,它们使用XCTest (Kiwi/XCTest和Specta),因为XCTest/XCTest不能在Xcode 6中构建。无法找到h。

fatal error: 'XCTest/XCTest.h' file not found
#import <XCTest/XCTest.h>

I noticed that XCTest.framework is no longer in the "Link Libraries with Binaries" build phase list, but that's fine because when I create a new project with Xcode 6 it appears the library is linked in automatically.

我注意到XCTest.framework不再在“与二进制文件的链接库”构建阶段列表中,但这很好,因为当我用Xcode 6创建一个新项目时,它会自动地链接到库中。

Perhaps of some relevency, my XCTest-needing dependencies are all brought in via Cocoapods.

也许有些关联,我的xctest需要的依赖项都是通过Cocoapods引入的。

Is there anything I'm unaware of that I need to update with my project?

有什么我没有意识到的,我需要更新我的项目?

11 个解决方案

#1


134  

Note: This may not be needed for any projects created in Xcode 7.

注意:在Xcode 7中创建的任何项目都不需要这样做。

CocoaPods had a fix for this here and here

可可豆在这里和这里都有固定的位置。


In order to fix this for any CocoaPod dependencies you need to add the following to FRAMEWORK_SEARCH_PATHS in any Pod target that requires XCTest (e.g. Kiwi, Specta, FBSnapshotTestCase, etc).

为了解决这个问题,您需要在任何需要XCTest(例如Kiwi, Specta, FBSnapshotTestCase,等等)的Pod目标中添加如下的framework_search_path。

$(PLATFORM_DIR)/Developer/Library/Frameworks

美元(PLATFORM_DIR)/开发/图书馆/框架

XCTest / XCTest。没有在Xcode 6中构建的旧项目中找到。

This will allow you to reference XCTest in any dependencies you may have. This may be fixed in a future update of CocoaPods, or the Pod you are referencing, so you may want to remove it later.

这将允许您在任何依赖项中引用XCTest。这可能会在未来更新的CocoaPods中修复,或者您正在引用的Pod,因此您可能希望稍后删除它。

It is not detrimental to earlier versions of Xcode so should be safe to use.

它对早期版本的Xcode并不有害,所以应该安全使用。

#2


33  

I was moving files in a project around. All you have to do is select your test files xxxTests.m etc. and in file inspector select target as test and not as a regular target.

我在一个项目中移动文件。您所要做的就是选择您的测试文件xxxTests。在文件检查器中选择目标作为测试,而不是作为常规目标。

#3


17  

I've noticed that XCTest is available to a test target only (in Xcode 6). If you are using using XCTest for any other target (for whatever reason), you will see the XCTest.h not found error.

我注意到XCTest只针对一个测试目标(在Xcode 6中)。如果您正在使用XCTest用于其他任何目标(出于某种原因),您将看到XCTest。h没有发现错误。

#4


11  

@squarefrog has the right answer but you'll have to keep doing that manually each time you update your pods :(

@squarefrog有正确的答案,但每次更新你的pod时,你必须手动操作:(

If you add this to your podfile it will automatically add the extra path for you. E.g. if you wanted to add $(PLATFORM_DIR)/Developer/Library/Frameworks to FRAMEWORK_SEARCH_PATHS for Specta:

如果将这个添加到您的podfile中,它会自动为您添加额外的路径。例如,如果您想为Specta的framework_search_path添加$(PLATFORM_DIR)/Developer/Library/框架:

post_install do |installer|
    target = installer.project.targets.find { |t| t.to_s == "Pods-Tests-Specta" }
    if (target)
        target.build_configurations.each do |config|
            s = config.build_settings['FRAMEWORK_SEARCH_PATHS']
            s = [ '$(inherited)' ] if s == nil;
            s.push('$(PLATFORM_DIR)/Developer/Library/Frameworks')
            config.build_settings['FRAMEWORK_SEARCH_PATHS'] = s
        end
    else
        puts "WARNING: Pods-Tests-Specta target not found"
    end
end

#5


9  

This error comes up when you have added a file where XCTest is being used outside of a test target. To fix this in AppCode, you can right click on any suspected file and select 'Manage Targets' then make sure only the test target is checked.

当您添加了一个在测试目标之外使用XCTest的文件时,会出现这个错误。要在AppCode中修复这个问题,您可以右键单击任何可疑文件并选择“管理目标”,然后确保只检查测试目标。

#6


2  

I have faced same issue after some time I have imported XCTest framework from build phases and solved the issue.

在我从构建阶段导入XCTest框架并解决了这个问题之后,我也遇到了同样的问题。

Build phases-> XCTest.Framework>clean and run. I hope it will be helpful to some one..

构建阶段- > XCTest。>清洁和运行框架。我希望这对某人有帮助。

for your reference...Import XCTest in to existing project

供你参考……将XCTest导入到现有项目中。

#7


1  

As of the time of writing, the latest version of Cocoapods (0.33.1) doesn't have a fix for the problem.

在撰写本文时,最新版本的Cocoapods(0.33.1)并没有解决问题。

But the cutting edge version does.

但最尖端的版本确实如此。

Follow this guide to set the latest version of Cocoapods up from source. I call mine pod-dev (covered in the guide) to distinguish it from the gem-installed version of pods.

按照这个指南,从源代码中设置最新版本的Cocoapods。我叫我的pod-dev(在指南中包含),以区别于安装在gemc上的pod。

The benefit of this approach is that you don't need extra scripting in your Podfile. You just have to remember to do a pod-dev install instead of the usual pod install.

这种方法的好处是,您不需要在Podfile中添加额外的脚本。你只需要记住做一个pod-dev安装而不是通常的pod安装。

#8


0  

This is the easiest work-around I've found. No project changes are necessary. And this change will persist until your next Xcode upgrade:

这是我找到的最简单的工作。不需要进行任何项目更改。这个更改将一直持续到您的下一个Xcode升级:

cd /Applications/Xcode6-Beta7.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk/Developer/Library/Frameworks
ln -s ../../../../../Library/Frameworks/XCTest.framework

#9


0  

On a project without Cocoapods (so not directly answering the OP's question but perhaps helpful for me or others in the future), we had the same issue. It was solved by replacing our previous OCTest items with XCTest. For example, a file MyApp.xcodeproj/project.pbxproj has this diff (shortened) ; - path = MyAppUnitTests.octest; sourceTree = BUILT_PRODUCTS_DIR; }; + path = MyAppUnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };

在一个没有Cocoapods的项目(所以没有直接回答OP的问题,但可能对我或将来的其他人有帮助),我们有同样的问题。用XCTest替换我们以前的OCTest项来解决这个问题。例如,一个文件MyApp.xcodeproj/project。pbxproj有这个diff(缩短);- path = MyAppUnitTests.octest;sourceTree = BUILT_PRODUCTS_DIR;};+ = MyAppUnitTests.xctest路径;sourceTree = BUILT_PRODUCTS_DIR;};

#10


0  

The best way to have an XCTest is to add it from the Test Nagigator (5th icon in the left pane).

拥有XCTest的最佳方法是将其从测试Nagigator(左窗格中的第5个图标)中添加。

Acting so, the new xx.m test file doesn't target (in the right pane) an app (in the left pane > Target, Wrapper Extension : app), but a bundle (Wrapper Extension: xctest)

这样,新的xx。m测试文件不针对(在右边的面板)一个应用程序(在左边的面板>目标,包装器扩展:app),但是一个包(包装器扩展:xctest)

  • the XCTest.framework remains in Red,
  • XCTest.framework仍然是红色的,
  • because of some modifications you can have the error 'XCTest/XCTest.h' file not found, it's because your file had got to target an app.
  • 由于一些修改,您可以有错误的XCTest/XCTest。文件没有找到,是因为你的文件已经锁定了一个应用程序。

#11


-3  

add the follow to framework search path

添加follow到框架搜索路径。

/Applications/Xcode6-Beta.app/Contents/Developer/Library/Frameworks

#1


134  

Note: This may not be needed for any projects created in Xcode 7.

注意:在Xcode 7中创建的任何项目都不需要这样做。

CocoaPods had a fix for this here and here

可可豆在这里和这里都有固定的位置。


In order to fix this for any CocoaPod dependencies you need to add the following to FRAMEWORK_SEARCH_PATHS in any Pod target that requires XCTest (e.g. Kiwi, Specta, FBSnapshotTestCase, etc).

为了解决这个问题,您需要在任何需要XCTest(例如Kiwi, Specta, FBSnapshotTestCase,等等)的Pod目标中添加如下的framework_search_path。

$(PLATFORM_DIR)/Developer/Library/Frameworks

美元(PLATFORM_DIR)/开发/图书馆/框架

XCTest / XCTest。没有在Xcode 6中构建的旧项目中找到。

This will allow you to reference XCTest in any dependencies you may have. This may be fixed in a future update of CocoaPods, or the Pod you are referencing, so you may want to remove it later.

这将允许您在任何依赖项中引用XCTest。这可能会在未来更新的CocoaPods中修复,或者您正在引用的Pod,因此您可能希望稍后删除它。

It is not detrimental to earlier versions of Xcode so should be safe to use.

它对早期版本的Xcode并不有害,所以应该安全使用。

#2


33  

I was moving files in a project around. All you have to do is select your test files xxxTests.m etc. and in file inspector select target as test and not as a regular target.

我在一个项目中移动文件。您所要做的就是选择您的测试文件xxxTests。在文件检查器中选择目标作为测试,而不是作为常规目标。

#3


17  

I've noticed that XCTest is available to a test target only (in Xcode 6). If you are using using XCTest for any other target (for whatever reason), you will see the XCTest.h not found error.

我注意到XCTest只针对一个测试目标(在Xcode 6中)。如果您正在使用XCTest用于其他任何目标(出于某种原因),您将看到XCTest。h没有发现错误。

#4


11  

@squarefrog has the right answer but you'll have to keep doing that manually each time you update your pods :(

@squarefrog有正确的答案,但每次更新你的pod时,你必须手动操作:(

If you add this to your podfile it will automatically add the extra path for you. E.g. if you wanted to add $(PLATFORM_DIR)/Developer/Library/Frameworks to FRAMEWORK_SEARCH_PATHS for Specta:

如果将这个添加到您的podfile中,它会自动为您添加额外的路径。例如,如果您想为Specta的framework_search_path添加$(PLATFORM_DIR)/Developer/Library/框架:

post_install do |installer|
    target = installer.project.targets.find { |t| t.to_s == "Pods-Tests-Specta" }
    if (target)
        target.build_configurations.each do |config|
            s = config.build_settings['FRAMEWORK_SEARCH_PATHS']
            s = [ '$(inherited)' ] if s == nil;
            s.push('$(PLATFORM_DIR)/Developer/Library/Frameworks')
            config.build_settings['FRAMEWORK_SEARCH_PATHS'] = s
        end
    else
        puts "WARNING: Pods-Tests-Specta target not found"
    end
end

#5


9  

This error comes up when you have added a file where XCTest is being used outside of a test target. To fix this in AppCode, you can right click on any suspected file and select 'Manage Targets' then make sure only the test target is checked.

当您添加了一个在测试目标之外使用XCTest的文件时,会出现这个错误。要在AppCode中修复这个问题,您可以右键单击任何可疑文件并选择“管理目标”,然后确保只检查测试目标。

#6


2  

I have faced same issue after some time I have imported XCTest framework from build phases and solved the issue.

在我从构建阶段导入XCTest框架并解决了这个问题之后,我也遇到了同样的问题。

Build phases-> XCTest.Framework>clean and run. I hope it will be helpful to some one..

构建阶段- > XCTest。>清洁和运行框架。我希望这对某人有帮助。

for your reference...Import XCTest in to existing project

供你参考……将XCTest导入到现有项目中。

#7


1  

As of the time of writing, the latest version of Cocoapods (0.33.1) doesn't have a fix for the problem.

在撰写本文时,最新版本的Cocoapods(0.33.1)并没有解决问题。

But the cutting edge version does.

但最尖端的版本确实如此。

Follow this guide to set the latest version of Cocoapods up from source. I call mine pod-dev (covered in the guide) to distinguish it from the gem-installed version of pods.

按照这个指南,从源代码中设置最新版本的Cocoapods。我叫我的pod-dev(在指南中包含),以区别于安装在gemc上的pod。

The benefit of this approach is that you don't need extra scripting in your Podfile. You just have to remember to do a pod-dev install instead of the usual pod install.

这种方法的好处是,您不需要在Podfile中添加额外的脚本。你只需要记住做一个pod-dev安装而不是通常的pod安装。

#8


0  

This is the easiest work-around I've found. No project changes are necessary. And this change will persist until your next Xcode upgrade:

这是我找到的最简单的工作。不需要进行任何项目更改。这个更改将一直持续到您的下一个Xcode升级:

cd /Applications/Xcode6-Beta7.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk/Developer/Library/Frameworks
ln -s ../../../../../Library/Frameworks/XCTest.framework

#9


0  

On a project without Cocoapods (so not directly answering the OP's question but perhaps helpful for me or others in the future), we had the same issue. It was solved by replacing our previous OCTest items with XCTest. For example, a file MyApp.xcodeproj/project.pbxproj has this diff (shortened) ; - path = MyAppUnitTests.octest; sourceTree = BUILT_PRODUCTS_DIR; }; + path = MyAppUnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };

在一个没有Cocoapods的项目(所以没有直接回答OP的问题,但可能对我或将来的其他人有帮助),我们有同样的问题。用XCTest替换我们以前的OCTest项来解决这个问题。例如,一个文件MyApp.xcodeproj/project。pbxproj有这个diff(缩短);- path = MyAppUnitTests.octest;sourceTree = BUILT_PRODUCTS_DIR;};+ = MyAppUnitTests.xctest路径;sourceTree = BUILT_PRODUCTS_DIR;};

#10


0  

The best way to have an XCTest is to add it from the Test Nagigator (5th icon in the left pane).

拥有XCTest的最佳方法是将其从测试Nagigator(左窗格中的第5个图标)中添加。

Acting so, the new xx.m test file doesn't target (in the right pane) an app (in the left pane > Target, Wrapper Extension : app), but a bundle (Wrapper Extension: xctest)

这样,新的xx。m测试文件不针对(在右边的面板)一个应用程序(在左边的面板>目标,包装器扩展:app),但是一个包(包装器扩展:xctest)

  • the XCTest.framework remains in Red,
  • XCTest.framework仍然是红色的,
  • because of some modifications you can have the error 'XCTest/XCTest.h' file not found, it's because your file had got to target an app.
  • 由于一些修改,您可以有错误的XCTest/XCTest。文件没有找到,是因为你的文件已经锁定了一个应用程序。

#11


-3  

add the follow to framework search path

添加follow到框架搜索路径。

/Applications/Xcode6-Beta.app/Contents/Developer/Library/Frameworks