Skip to content

Clarify that @AutoConfigureWebTestClient binds WebTestClient to mock infrastructure #29890

@SimoneGiusso

Description

@SimoneGiusso

This follows the issue Improve documentation for uri(URI) method in WebTestClient regarding base URI where all details are explained.

To summarize:

  • Using WebTestClient without @AutoConfigureWebTestClient and with @SpringBootTest(webEnvironment = RANDOM_PORT), make the integration tests not working without the base URI (Error: Connection refused).
  • Using WebTestClient with @AutoConfigureWebTestClient and @SpringBootTest(webEnvironment = RANDOM_PORT), make the tests work without the base URI.

I think this is not expected and it's not coherent from a developer prospective or at least need to be documented. See the link above for more details.

What I expect is that this code:

@SpringBootTest(webEnvironment = RANDOM_PORT) @ActiveProfiles("test") @Sql("classpath:sql/my_sql.sql") @Import(TestConfig.class)
 URI uri = UriComponentsBuilder .fromUriString(MY_URL) .queryParam("year", 2005) .buildAndExpand() .toUri(); client.get() .uri(uri) .exchange() .expectStatus() .is2xxSuccessful();

has the same behaviour with the @AutoConfigureWebTestClient since @SpringBootTest by default configures a WebTestClient

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions