AliSoftware / OHHTTPStubs

Stub your network requests easily! Test your apps with fake network data and custom response time, response code and headers!
MIT License
5.03k stars 602 forks source link

Unable to import OHHTTPStubsSwift from swift package manager dependency #324

Closed pavm035 closed 3 years ago

pavm035 commented 4 years ago

New Issue Checklist

Environment

Issue Description

I'm trying to add OHHTTPStubs ad my pakcage dependency in my Swift package, I can import OHHTTPStubs but not OHHTTPStubsSwift into my project, i have added dependency like this .package(url: "https://github.com/AliSoftware/OHHTTPStubs.git", .upToNextMajor(from: "9.0.0")),

.testTarget(
            name: "MyFrameworkTests",
            dependencies: [
                "MyFramework",
                "OHHTTPStubs",
                "OHHTTPStubsSwift" // <= Error here, i tried removing it also but it remains same
            ],
            resources: [
                .process("TestData")
            ]
        ),

NOTE: There is someone posted similar problem here https://stackoverflow.com/questions/61069763/swift-package-manifest-for-multiple-library-products

Complete output when you encounter the issue (if any)
xxxx/Package.swift: dependency 'OHHTTPStubsSwift' in target 'MyFrameworkTests' requires explicit declaration; reference the package in the target dependency with '.product(name: "OHHTTPStubsSwift", package: "OHHTTPStubs")'
JZDesign commented 4 years ago

That error tells you how to fix this.

xxxx/Package.swift: dependency 'OHHTTPStubsSwift' in target 'MyFrameworkTests' requires explicit declaration; reference the package in the target dependency with '.product(name: "OHHTTPStubsSwift", package: "OHHTTPStubs")'

In the test target dependencies use this .product(name: "OHHTTPStubsSwift", package: "OHHTTPStubs")

eseay commented 4 years ago

Change your .testTarget to:

.testTarget(
    name: "MyFrameworkTests",
    dependencies: [
        "MyFramework",
        .product(name: "OHHTTPStubsSwift", package: "OHHTTPStubs")
    ]
)

It also appears you can now do the following, which I have opted for:

.testTarget(
    name: "MyFrameworkTests",
    dependencies: [
        .target(name: "MyFramework"),
        .product(name: "OHHTTPStubsSwift", package: "OHHTTPStubs")
    ]
)