We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OHHTTPStubs
Hi, I am trying to use OHHHTTPStubs in my tests, but they are failing.
Since I am using the Swift Package Manager, I've added OHHTTPStubs as a dependency:
// swift-tools-version: 5.9 import PackageDescription let package = Package( name: "Sdk", platforms: [.macOS(.v14), .iOS(.v15)], products: [ .library( name: "Sdk", targets: ["Sdk"]), .executable( name: "Example", targets: ["SdkExample"] ), ], dependencies: [ .package( url: "https://github.com/AliSoftware/OHHTTPStubs.git", from: "9.0.0" ) ], targets: [ .target( name: "Sdk", dependencies: ["Org", "Api"]), .executableTarget( name: "SdkExample", dependencies: ["Sdk"] ), .testTarget( name: "SdkTests", dependencies: ["Sdk", "OHHTTPStubs", "OHHTTPStubsSwift"]), .target(name: "Org", dependencies: ["SdkInternal", "Shared"]), .target(name: "Api", dependencies: ["SdkInternal", "Shared"]), .target(name: "Shared", dependencies: ["SdkInternal"]), .target(name: "SdkInternal", dependencies: []), ] )
Then I created a very basic test:
import Foundation import OHHTTPStubs import XCTest @testable import Sdk @testable import Shared final class SdkTests: XCTestCase { func testExample() async throws { stub(condition: isHost("my-api.com")) { _ in let stubData = """ { "id": 1, } """.data(using: .utf8)! return OHHTTPStubsResponse(statusCode: 200) } let sdk = Sdk(baseUrl: "http://my-api.com") var params = SdkRequestParams() params.headers["Authorization"] = "Bearer token" let getByIdResult = try await sdk.org.getById(id: "1", params: params) XCTAssertEqual(getByIdResult.metadata.statusCode, 200) } }
However, when I try to run it, I get this error:
error: 'sdk': product 'OHHTTPStubsSwift' required by package 'sdk' target 'SdkTests' not found. Did you mean 'OHHTTPStubsSwift'?
If I remove the import OHHTTPStubsSwift, I get these errors:
import OHHTTPStubsSwift
error: cannot find 'stub' in scope stub(condition: isHost("my-api.com")) { _ in ^~~~ error: cannot find 'isHost' in scope stub(condition: isHost("my-api.com")) { _ in ^~~~~~ error: cannot find 'OHHTTPStubsResponse' in scope return OHHTTPStubsResponse(statusCode: 200) ^~~~~~~~~~~~~~~~~~~ error: fatalError error: fatalError
I am new to Swift. Could you help me?
The text was updated successfully, but these errors were encountered:
In Package.swift:
Package.swift
.testTarget( name: "SdkTests", dependencies: [ "Sdk", .product(name: "OHHTTPStubs", package: "OHHTTPStubs"), .product(name: "OHHTTPStubsSwift", package: "OHHTTPStubs") ] )
in your unit test:
import OHHTTPStubs import OHHTTPStubsSwift
Sorry, something went wrong.
No branches or pull requests
New Issue Checklist
OHHTTPStubs
for your project sectionEnvironment
Issue Description
Hi, I am trying to use OHHHTTPStubs in my tests, but they are failing.
Since I am using the Swift Package Manager, I've added OHHTTPStubs as a dependency:
Then I created a very basic test:
However, when I try to run it, I get this error:
If I remove the
import OHHTTPStubsSwift
, I get these errors:I am new to Swift. Could you help me?
The text was updated successfully, but these errors were encountered: