All acceptance tests use TestRestTemplate via WebIntegrationTest:
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) |
|
@AutoConfigureMockMvc |
|
public abstract class WebIntegrationTest { |
This requires a full web server configuration, as provided by SpringBootTest.WebEnvironment.DEFINED_PORT (or RANDOM_PORT).
However, for most tests this is overkill, and it is very slow.
Moreover, TestRestTemplate will be deprecated in spring-boot 4.2. Note that the underlying RestTemplate was already deprecated in spring-boot 4.0.0.
Instead of TestRestTemplate with full web server setup, we should consider using MockMvc (or MockMvcTester), together with the default SpringBootTest.WebEnvironment.MOCK.
An even better option is to use the new RestTestClient which supports both full server tests and mock tests:
RestTestClient is an HTTP client designed for testing server applications. It wraps Spring’s RestClient and uses it to perform requests, but exposes a testing facade for verifying responses. RestTestClient can be used to perform end-to-end HTTP tests. It can also be used to test Spring MVC applications without a running server via MockMvc.
related:
All acceptance tests use
TestRestTemplateviaWebIntegrationTest:FAIRDataPoint/src/test/java/org/fairdatateam/fairdatapoint/WebIntegrationTest.java
Lines 38 to 40 in bfb5d49
This requires a full web server configuration, as provided by
SpringBootTest.WebEnvironment.DEFINED_PORT(orRANDOM_PORT).However, for most tests this is overkill, and it is very slow.
Moreover,
TestRestTemplatewill be deprecated in spring-boot 4.2. Note that the underlyingRestTemplatewas already deprecated in spring-boot 4.0.0.Instead of
TestRestTemplatewith full web server setup, we should consider usingMockMvc(orMockMvcTester), together with the defaultSpringBootTest.WebEnvironment.MOCK.An even better option is to use the new RestTestClient which supports both full server tests and mock tests:
related: