WeTransfer / Mocker

Mock Alamofire and URLSession requests without touching your code implementation
MIT License
1.12k stars 96 forks source link

version 2.3.0 seems to introduce test error in non-test targets #60

Closed roksollc closed 3 years ago

roksollc commented 4 years ago

Undefined symbol: __swift_FORCE_LOAD_$_XCTestSwiftSupport

Using version 2.2.0, no error results.

roksollc commented 4 years ago

I believe the problem is that XCTest is imported in XCTest+Mocker.swift, which is part of the Sources folder.

AvdLee commented 4 years ago

@roksollc you've probably added Mocker to your main target. XCTest is only available from test targets and Mocker is designed to be used within tests only.

The easiest fix would be to reintegrate Mocker using SPM and making sure the selected target in the final step is set to your test target:

image

roksollc commented 4 years ago

That's a shame you're pigeon-holing the product, as we were using it as a means to run/test our app for new features w/o using bandwidth. I never encountered anything that suggested the product was meant solely for XCTest usage...and it wasn't forced that way until the recent changes.

AvdLee commented 4 years ago

@roksollc I would be open to support that scenario, I was assuming nobody would use it that way.

If we can find a way to support both I would be happy to approve any PR for that! Main issue would be to only include XCTest for test targets.

iGranDav commented 4 years ago

#if canImport(XCText) could do the trick 👌 we will make a PR for that since we are also using this really nice library for our UITests.

AvdLee commented 4 years ago

@iGranDav in that case I'm reopening this issue so that it can be closed with your PR!

ericpassmore commented 4 years ago

May also be resolved by changing build options ENABLE_TESTING_SEARCH_PATHS to YES

github-actions[bot] commented 3 years ago

This issue is stale because it has been open for 30 days with no activity. Remove the Stale label or comment or this will be closed in 10 days.

teameh commented 2 months ago

This never made it into the lib did it? Would be great to use mocker for an app that needs a "demo" mode to work without a backend.

teameh commented 1 month ago

if canImport(XCText) could do the trick 👌 we will make a PR for that since we are also using this really nice library for our UITests.

Nope..#if canImport(XCText) will always be true, even if ENABLE_TESTING_SEARCH_PATHS is not set.

Adding ENABLE_TESTING_SEARCH_PATHS to the build options indeed seems to work... but, it will stop all your SwiftUI previews from compiling 😞

I've forked the project for now, removing XCTest https://github.com/WeTransfer/Mocker/compare/master...teameh:Mocker:without-xctest for a version that can be used in main targets to mock the network for using in demo modes.

AndrewSB commented 16 hours ago

could you PR this? i'm only using Mocker for SwiftUI previews, so my main targets depend on it. i can't set ENABLE_TESTING_SEARCH_PATHS to false, since it would break those previews