[Spring Boot Test] Spring Boot Test
Spring Boot Test
FAQs
No qualifying bean of type ‘org.springframework.boot.test.web.client.TestRestTemplate’ available
1 | Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.test.web.client.TestRestTemplate' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} |
TestRestTemplate
is only auto-configured when @SpringBootTest
has been configured with a webEnvironment that means it starts the web container and listens for HTTP requests. For example:
Note the use of webEnvironment=RANDOM_PORT
to start the server with a random port (useful to avoid conflicts in test environments)
1 |
|
References
[1] Getting Started | Testing the Web Layer - https://spring.io/guides/gs/testing-web/