Effectively Test Spring's RestTemplate with @RestClientTest

  Рет қаралды 8,974

Philip Riecks

Philip Riecks

Күн бұрын

Пікірлер: 10
@rieckpil
@rieckpil 4 жыл бұрын
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
@msraju2326
@msraju2326 2 жыл бұрын
Thanks
@tiyasha01
@tiyasha01 Жыл бұрын
Hi,how can i test timeout set on resttemplatebuilder,that we should have Connect Exception if timeout is exceeded?
@AmNotLegend
@AmNotLegend 3 жыл бұрын
is this @RestClientTest used for testing third party API? then what we can conclude from mocked responses?
@rieckpil
@rieckpil 3 жыл бұрын
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.
@AmNotLegend
@AmNotLegend 3 жыл бұрын
@@rieckpil good explanation; thanks
@mrowox
@mrowox Жыл бұрын
What if I wasn't using getForObject but instead using exchange? How do I test that?
@rieckpil
@rieckpil Жыл бұрын
that doesn't matter at all as we're mocking on the HTTP level.
@SirWolf2018
@SirWolf2018 3 жыл бұрын
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.
@rieckpil
@rieckpil 3 жыл бұрын
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.
Testing Spring Boot Applications Masterclass - Sneak Peek
16:53
Philip Riecks
Рет қаралды 1,9 М.
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 36 МЛН
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН
🚀 New in Spring Framework 6.1: RestClient
13:16
Maciej Walkowiak 🍃 Spring Academy
Рет қаралды 11 М.
Spring Boot 3 Integration Testing With TestContainers
22:08
Daily Code Buffer
Рет қаралды 15 М.
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 36 МЛН