Mocks/fakes and other non-live dependencies #408
lukeredpath
started this conversation in
General
Replies: 1 comment
-
I mostly use 1. One work around for the limitation is to use another flag than DEBUG you can then build in release or debug mode. When building for the store you can disable the flag to be sure those are excluded. This is pretty easy to do in Xcode with a custom scheme. When using SPM you can pass unsafeFlags but I don't think you have an easy way to pass them from Xcode. One nice thing I found is to map on the targets after they are defined so you can have one place for those thing like:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This isn't solely a TCA concern but I'm posting it here as it goes hand in hand with the style of API design and dependency management promoted by TCA - I'm curious to know if and how people are taking steps to avoid that they don't accidentally ship their apps running any kind of non-live dependency.
For example, we may commonly define:
Both are generally used in our tests but may also be used in things like SwiftUI previews, or even as stand-ins before we've written the live dependencies while we are developing a new feature.
My preference is to try and keep these mocks/example values close to the thing they are mocking - so if I were breaking these into separate modules (e.g. products in a Swift package) I would generally include them in the same module as the interface. They could just as easily be in your main app target if you're not using a highly modular approach.
I can think of a few safeguards about accidentally shipping code that was using a mock dependency:
1. Wrap all non-release code in a compiler directive, e.g.:
This is a fairly straightforward approach that we've been using on our current project but it can lead to some issues:
if #DEBUG
statements (just like you used to have to in the early betas).2. Write integration tests for each feature
We lean on
TestStore
and mock dependencies to drive a lot of our tests and it works great. However there's probably room for at least a couple of integration-style tests that exercise your live dependencies and make sure everything is wired together correctly. Integration style tests tend to be slower and more brittle as they often depend on external resources so its preferable to write fewer of these.3. Do nothing
This seems like a valid option. Perhaps the risk of mocks slipping into release code in place of live dependencies is so small that its not worth worrying about. The combination of manual testing, some automated testing (integration + UI tests) and code review/pairing practices should be enough to safeguard against this.
Anyone got any views on this or alternative approaches?
Beta Was this translation helpful? Give feedback.
All reactions