-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Make integration testing of webclient easier with @MockServerResponse annotation. #45652
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
Comments
Thanks for the suggestion. I'm not convinced that involving Docker is worth it here. It's generally most beneficial when you want to test your application against a real running service rather than a mocked or in-memory alternative that may not be exactly equivalent. For testing code that uses WebClient (or RestClient), we generally recommend something like OkHttp MockWebServer instead. |
Hey thanks on fast response. I usually do what you described even put second service in network mode with dependency it uses (database, kafka whatever it requires). Problem here is I want response from 3rd party service which I don't have an access to, so I cant spin image. I want to do proper integration test which means lifting context. Both okhttp and mockservercontainer will do same, one will start container, other will start the server without container. Annotation could work for both right? I am not testing what I am sending since unit tests are covering business logic (various use cases with linked tickets). Integration tests with 3rd party whatever I do is a mock. Even sometimes if you assert what you send doesn't matter since docs can be different than api behaviour (so sys test is only way). I fully understand what you mean but I think okhttp could benefit of the same annotation? Also I see a lot of cases which this annotation wouldn't help, for example if you want to assert a headers or something specific. If you don't see benefits I can close the ticket :) |
Closing this issue in favor of spring-projects/spring-framework#34892 where we are going to better document how to test clients. If we see new candidates features for Boot there, we can reconsider. Thanks! |
Uh oh!
There was an error while loading. Please reload this page.
When doing full blown integration tests with
@SpringBootTest
and havingwebclient
reach to 3rd party services instead of mocking it or injectingMockServerClient
client and mockingMockignServerContainer
support@MockServerResponse
annotation should support container mock out of the box.When Testcontainer of type MockServer is created and annotated with
@ServiceConnection
.We can annotate test class
In background
MockServer
container will be mocked withmockServerClient
for endpoint and method specified in annotation and with given response out of the box. This way we remove a lot of boilerplate code for simpler integrations which would be written withmockServerClient
, also we are making test more readable by clearly extracting response in an annotation.If this is something you think is good idea I am willing to contribute. :)
The text was updated successfully, but these errors were encountered: