Import XCTest into a dynamic framework

∥☆過路亽.° 提交于 2020-01-11 17:40:16

问题


I have a project where I have created a dynamic framework. Inside the framework itself, not the framework's 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
}

They are utility methods to assert that a clojure is raising an exception. It's to make up for the missing Swift's XCTAssertThrows().

Of course I have to import the XCTest framework to be able to use XCTAssert* methods. But I am not able to achieve it. I keep receiving an error that a framework with that name is not available.

Do you have any idea how to successfully import XCTest?

Thank you very much


回答1:


I've run into similar issue and used build settings from Nimble project. To fix issue:

1: Add to Other Linker Flags:

-weak_framework XCTest -weak-lswiftXCTest

2: Add to Framework Search Paths:

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

Now dynamic framework can import XCTest.

Sidenote: I also wanted to write something similar. I've ended up creating mini-framework for unit testing error handling in Swift, maybe someone will find it useful. Works both with CocoaPods and Carthage.



来源:https://stackoverflow.com/questions/33370408/import-xctest-into-a-dynamic-framework

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!