如何调试 @SpringBootTest 中的嵌套 Web 应用程序
我正在尝试运行以下自动化测试:
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("");
}
}
我在 IntelliJ Idea 调试器下运行它,并且可以跟踪 testMyUrl
函数。不幸的是,控制器代码内的任何断点都会被忽略。这可能是因为它是在单独的进程内执行的,调试器未附加到该进程。
问题是:是否可以自动化或轻松附加到此过程?我可以使用 Quarkus 插件在 Quarkus 中执行此操作。 Spring 是否可以做同样的事情?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论