Skip to content
New issue

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

Opt out for MOCKING compile flag #45

Open
mihaicris-adoreme opened this issue Apr 29, 2024 · 2 comments
Open

Opt out for MOCKING compile flag #45

mihaicris-adoreme opened this issue Apr 29, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@mihaicris-adoreme
Copy link

mihaicris-adoreme commented Apr 29, 2024

Just a thought..

I had a situation when I needed to have a null pattern implementation for production environment of a mockable protocol which was easily created with Mock..(policy: .relaxed). However by default all mocks are under #if MOCKING compiler flag.
Would that be possible to opt out for the MOCKING flag when generating mocks? Such that the mock can be used in release configuration.
Something like this:

@Mockable(underFlag: false) // or better naming
protocol ... { }

Currently I configure MOCKING also for release config, but this makes all protocols available in release. I only needed for some protocols.
Alternative is to create the implementation for release config manually without using the Mock generated.

@Kolos65
Copy link
Owner

Kolos65 commented May 9, 2024

Hey @mihaicris-adoreme, sorry for the late response!

Extending the library with more control over the compile flag is a great idea, it already crossed my mind!

That being said, I would not suggest using the generated mocks in production as a default implementation or similar. They are designed for testing and will keep track of every function call, store return values, etc..., that can result in poor performance and unexpected results when used as a "real" implementation. The main use case for the generated mocks was meant to be SwiftUI previews and unit testing. If I needed relaxed mock implementations in prod, I would create them manually.

Regardless, I will happily consider this feature request as it could help in different architectures and make the library usage more seamless.

Im thinking of letting users provide the flag as an optional string literal with a default "MOCKING" value like:

@Mockable(condition: "DEBUG")
protocol Service {}

or if no flag is desired:

@Mockable(condition: .none)
protocol Service {}

@mihaicris-adoreme
Copy link
Author

Hi @Kolos65 , thanks for the comments, and considering the flag options. You are right, I'll define custom implementations manually for production.!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants