If you encounter any issue while running the test, try to remove the @Bean CommandLineRunner from the main application class. I forgot to mention this
@msraju23262 жыл бұрын
Thanks
@tiyasha01 Жыл бұрын
Hi,how can i test timeout set on resttemplatebuilder,that we should have Connect Exception if timeout is exceeded?
@AmNotLegend3 жыл бұрын
is this @RestClientTest used for testing third party API? then what we can conclude from mocked responses?
@rieckpil3 жыл бұрын
the @RestClientTest can be used to test HTTP clients that access a third part API. Testing the third party API itself is hard to achieve and the responsibility of the third party I would say. The benefits of this approach (over extensive mocking when writing classic unit tests for such HTTP clients) are: testing error scenarios (HTTP 500), verify the serialization works as expected, test fallback scenarios, etc.
@AmNotLegend3 жыл бұрын
@@rieckpil good explanation; thanks
@mrowox Жыл бұрын
What if I wasn't using getForObject but instead using exchange? How do I test that?
@rieckpil Жыл бұрын
that doesn't matter at all as we're mocking on the HTTP level.
@SirWolf20183 жыл бұрын
Cool, but if you don't static import your DSL static methods, then you just add painful verbosity. You can recognize a need for a static import when the name of the class does not add anything to the meaning of the method name.
@rieckpil3 жыл бұрын
I'm not sure why you copied the same comment four times, but thanks for the hint :) I explicitly picked the non-static import to avoid (especially for Java newcomers) confusion to understand where this method is coming from immediately. I'm also favoring the static import for my day-to-day projects to make it as concise as possible.