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

Create a test artifact to help with testing code that depends on connect-kotlin generated code #59

Open
erawhctim opened this issue Aug 4, 2023 · 2 comments

Comments

@erawhctim
Copy link
Contributor

When testing code that has a dependency on one of the API clients/endpoints that connect-kotlin generates, consumers have to rely on mocking frameworks to stub out the generated calls and replace their responses.

This generally works, due to the maturity of mocking frameworks on the JVM, but as an alternative (for projects that don't want to import/use mocking frameworks), buf/the BSR could generate fake API client implementations for testing purposes (similar to how the connect-swift-mocks plugin works).

@ln-12
Copy link

ln-12 commented Sep 6, 2023

Hey @erawhctim, did you find a suitable approach to mock the dependency yet?

I will probably do it by implementing the methods from the generated client interfaces using my mock data and provide these implementations via dependency injection instead of the actual client implementations. Just wanted to know if you maybe found another approach.

@erawhctim
Copy link
Contributor Author

Hey @erawhctim, did you find a suitable approach to mock the dependency yet?

I will probably do it by implementing the methods from the generated client interfaces using my mock data and provide these implementations via dependency injection instead of the actual client implementations. Just wanted to know if you maybe found another approach.

Sorry for the late reply here! Your solution matches ours: we're using overloaded constructors that allow us to supply a mocked instance of the generated client in tests, while injecting the ProtocolClient and manually constructing those client instances instead.

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

No branches or pull requests

2 participants