2

I'm writing a reusable framework around XCTest for UI testing of several of our projects. For this I created a Cocoa Touch Framework project that I want to share via pods.

Is it possible to include XCTest into such a project (without extra test targets)? I'm getting errors that the XCTest module cannot be found even though I've linked XCTest.framework in the build phases.

BadmintonCat
  • 9,416
  • 14
  • 78
  • 129
  • See the answer here for an alternative method not involving Pods: https://stackoverflow.com/questions/54147582/how-to-link-xctest-dependency-to-production-main-target – brthornbury Jan 16 '19 at 02:01

1 Answers1

9

You should add $(PLATFORM_DIR)/Developer/Library/Frameworks into Framework Search Paths which in the Build Settings of your framework target. Basically, you don't have to link your framework against XCTest.framework.

Also, if you're going to share the framework via pods you can add following code to your podspec file:

Pod::Spec.new do |s|
  ...
  s.weak_framework = "XCTest"
  s.pod_target_xcconfig = {
    'FRAMEWORK_SEARCH_PATHS' => '$(inherited) "$(PLATFORM_DIR)/Developer/Library/Frameworks"',
  }
  ...
end
imnosov
  • 856
  • 10
  • 16
  • Awesome! Thanks for the quick help! – BadmintonCat Jun 14 '17 at 04:48
  • How import files in XCUITest Target from such pod? – Degard Dec 18 '17 at 08:46
  • 3
    This could be improved slightly by using the more specific DEVELOPER_FRAMEWORKS_DIR as the value. It resolves to the same dir as $(PLATFORM_DIR)/Developer/Library/Frameworks – danielpunkass Apr 28 '18 at 16:17
  • 2
    As of Xcode 9, `DEVELOPER_FRAMEWORKS_DIR` no longer resolves to a sub-path of `PLATFORM_DIR` – hence `$(PLATFORM_DIR)/Developer/Library/Frameworks` is the correct search path now. – adib Aug 11 '18 at 17:16