Allow tests to initialize non-stubbed dependencies #185
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add flag
allow-tests-to-init-real-dependencies
that will force all dependency resolver methods to be declared asinternal
rather thanprivate
orfileprivate
so that any@Testable import
of the generated code is able to initialize both the dependency container and access all of the DependencyResolvers. Note that this does NOT change any of the test mock generation, this is altering the access level of the real dependencies to be able to facilitate customization of test dependencies. It is then possible to mix and match real and mocked dependencies based on your test setup. Previously this was not possible because the MainDependencyContainer initializer was private, along with all of the dependency resolvers. Without setting this flag, there is no impact to code generation so this change is fully backward compatible.For example, now inside of unit tests for some
CoolSampleApp
, you would be able to do this:It is still possible to use the
tests
flag to generate stubbed dependencies and use those alongside each other. For example, you can now mix and match real and mocked dependencies for a class under test to be able to do integration or feature level tests. Continuing thetextExample()
from above, you may see something like this:Also update dependencies and tools versions in the package so that it can compile with modern tool chains (Xcode 16.x, Swift 5).