首页 > 解决方案 > Swift Package Manager,如何处理夹具?

问题描述

我正在寻找将DVR集成到我正在编写的 HTTP 请求繁重的库的测试中。我正在使用 Swift 包管理器(在 macOS 10.15 上使用 Xcode 11 Beta)来管理我的依赖项,但我不确定如何将 DVR 生成的固定装置包含到我的测试目标中。如何将我的设备从 DVR 添加到我的测试目标?

我尝试使用默认的 Session 配置以及尝试使用Session(outputDirectory: "Fixtures", cassetteName: "example", testBundle: .main, backingSession: .shared)

我的包文件如下:

// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "Example",
    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
            name: "Example",
            targets: ["Example"]),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        .package(url: "https://github.com/venmo/DVR.git", from: "2.0.0")
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(
            name: "Example",
            dependencies: []
        ),
        .testTarget(
            name: "ExampleTests",
            dependencies: ["Example", "DVR"]
        )
    ]
)

运行测试时,出现错误[DVR] Persisted cassette at Fixtures/example.json. Please add this file to your test target

我不确定如何将此目录添加到我的测试目标。

标签: swiftfixturesswift-package-manager

解决方案


从 Swift 5.1 开始,这似乎是不可能的。斯威夫特票:SR-2866


推荐阅读