热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

将XCTest导入动态框架-ImportXCTestintoadynamicframework

IhaveaprojectwhereIhavecreatedadynamicframework.Insidetheframeworkitself,notthefram

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().

它们是用于断言clojure引发异常的实用方法。这是为了弥补失踪的Swift的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.

当然,我必须导入XCTest框架才能使用XCTAssert *方法。但我无法实现它。我一直收到一个错误,即该名称的框架不可用。

Do you have any idea how to successfully import XCTest?

你知道如何成功导入XCTest吗?

Thank you very much

非常感谢你

1 个解决方案

#1


15  

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

我遇到了类似的问题并使用了Nimble项目的构建设置。解决问题:

1: Add to Other Linker Flags:

1:添加到其他链接器标志:

-weak_framework XCTest -weak-lswiftXCTest

-weak_framework XCTest -weak-lswiftXCTest

2: Add to Framework Search Paths:

2:添加到框架搜索路径:

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

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

Now dynamic framework can import XCTest.

现在动态框架可以导入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.

旁注:我也想写类似的东西。我最终在Swift中为单元测试错误处理创建了迷你框架,也许有人会发现它很有用。适用于CocoaPods和Carthage。


推荐阅读
author-avatar
我爱你800916
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有