MakeAWishFoundation / SwiftyMocky

Framework for automatic mock generation. Adds a set of handy methods, simplifying testing. One of the best and most complete solutions, including generics support and much more.
MIT License
1.03k stars 103 forks source link

SwiftUI previews do not work when using SwiftyMocky with iOS #231

Closed andlang closed 4 years ago

andlang commented 4 years ago

I included SwiftyMocky (3.4.0) in my iOS project with the Swift Package Manager. When I try to build the SwiftUI preview, the build fails in the dependency ShellOut with “Class Process is unknown” (it’s only available in macOS) . It seems, that the preview wants to build all of the dependencies, no matter what platform is supported. I could only solve the issue in removing all of the dependencies (for the SwiftyMockyCLI).

Is it possible, to make two packages? One for SwiftyMocky and one for SwiftyMockyCLI? In that way, there wouldn’t be an issue with the SwiftUI preview.

Maybe it will also be solved with: https://github.com/apple/swift-evolution/blob/master/proposals/0273-swiftpm-conditional-target-dependencies.md

pballart commented 4 years ago

Same issue here. How did you manage to remove the SwiftyMockyCLI dependencies but still keep SwiftyMocky running for the tests?

amichnia commented 4 years ago

Hi guys. I will look into that over the weekend. In general, I think the problem is that we used originally SPM for CLI tool, which of course would not work in test targets.

andlang commented 4 years ago

@pballart I still use the legacy way with sourcery and a yaml config (https://github.com/MakeAWishFoundation/SwiftyMocky/blob/master/guides/Legacy.md). Therefore I could remove all targets from Package.swift except “SwiftyMocky”. But that was just a quick fix.

glyuck commented 4 years ago

I've faced the same issue. As a workaround, I install SwiftyMocky runtime via Carthage and the SwiftyMockyCLI via Mint.

Przemyslaw-Wosko commented 4 years ago

Since we want to be ready for SwiftUI ASAP, i will try to help @andrzejmichnia resolve this issue

kzietek commented 4 years ago

For those using SPM I made a workaround by removing all things related to CLI from Package.swift:

  1. File > Swift Packages > Reset package caches
  2. Add git@github.com:kzietek/SwiftyMocky.git with branch NoCLI.
  3. Be sure to select your test target when prompted.

As a side effect, preview builds much faster.

pballart commented 4 years ago

I just tried it and it works fine! 🎉

g-amichnia commented 4 years ago

Should be fixed in 4.0.0

chkpnt commented 4 years ago

I just updated SPM to the latest commit of SwiftyMocky and can confirm: SwiftUI-Preview works :-) Thank you!