Lance Kind
Lance Kind

Reputation: 1091

Add xctest dependency to Xcode 7 project

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 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?

Upvotes: 1

Views: 805

Answers (2)

HardikDG
HardikDG

Reputation: 6112

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

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

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

Upvotes: 1

Jon Reid
Jon Reid

Reputation: 20980

Show the File Inspector and check the Target Membership on EmptyTest.swift. I'm betting you added it to the production target, when it should be in the test target instead.

Upvotes: 0

Related Questions