Import XCTest into a dynamic structure

I have a project in which I created a dynamic structure. Inside the structure itself, and not as part of the framework tests, I have the following file:

import Foundation import XCTest public func assertThrowsException(function: () throws -> Void) { XCTAssertTrue(doesItThrowException(function)) } public func assertDoesNotThrowsException(function: () throws -> Void) { XCTAssertFalse(doesItThrowException(function)) } private func doesItThrowException(function: () throws -> Void) -> Bool { do { let _ = try function() } catch { return true } return false } 

These are utilities to claim that clojure throws an exception. This compensates for the missing Swift XCTAssertThrows ().

Of course, I need to import the XCTest framework in order to use the XCTAssert * methods. But I can’t achieve this. I get an error all the time that a framework with this name is not available.

Do you know how to import XCTest successfully?

Thank you very much

+6
source share
1 answer

I ran into a similar problem and used the build settings from the Nimble project. To fix the problem:

1: Add to other linker flags:

-weak_framework XCTest -weak-lswiftXCTest

2: add in Framework search paths:

$(DEVELOPER_FRAMEWORKS_DIR) $(PLATFORM_DIR)/Developer/Library/Frameworks

Now the dynamic structure can import XCTest.

Sidenote: I also wanted to write something like that. I ended up creating a mini-framework for handling module testing errors in Swift , maybe someone will find this useful. Works with both CocoaPods and Carthage.

+11
source

All Articles