Are there any properties available in Spring Boot to configure the @Autowired WebTestClient? For instance, how to set the servlet context path (or just some base path for that matter) on WebTestClient?
Here's how my web tests are configured now:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
public class MyTestClass{
@Autowired
private WebTestClient cl;
//the rest of it
}
In other words, what is Spring Boot equivalent of
WebTestClient client = WebTestClient.bindToServer()
.baseUrl("http://localhost:<random port>/myServletContext").build();
I didn't find anything useful in documentation: https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
building webTestClient using current application context, no need to hardcode uri and port number
@Autowired
ApplicationContext context;
@Autowired
WebTestClient webTestClient;
@Before
public void setup() throws Exception {
this.webTestClient = WebTestClient.bindToApplicationContext(this.context).build();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With