'How to debug nested web application inside @SpringBootTest

I am trying to run the following automated test:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class MyControllerTest {

    @LocalServerPort
    int port;

    @Autowired
    TestRestTemplate rest;

    private String myUrl() {
        return String.format("http://localhost:%d/...", port);
    }

    @Test
    public void testMyUrl() {
        String response = rest.getForObject(myUrl(), String.class);
        System.out.println("");
    }

}

I am running it under IntelliJ Idea debugger and I can trace testMyUrl function. Unfortunately, any breakpoints inside controller code is ignore. This is probably because it is executed inside separate process, which debugger is not attached to.

The question is: is it possible to automate or make easy attaching to this process? I was able to do this in Quarkus with Quarkus plugin. Is it possible to do the same with Spring?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source