首页 > 解决方案 > 调试器、@SpringBootTest 和 Gradle

问题描述

我是 Spring Boot 和 Gradle 的新手,无法弄清楚如何暂停 JUnit 测试并使用调试器连接到它们。

我在命令行上调用自动化测试gradlew build。我想要的是在它到达测试任务并等待调试器连接时暂停执行。

JUnit 测试类的注释如下:

@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles("test")
@AutoConfigureMockMvc

我已经尝试将用于调试的 JVM 参数添加到 gradle.properties 文件中,但我仍然无法让它暂停,更不用说在调试器的端口上监听了。我不确定要为您提供什么信息——请在评论中询问我的文件、代码或设置。

标签: spring-bootgradlejunitautomated-tests

解决方案


@奥米德。谢谢你的链接。解决方案很简单。

更新:不要使用gradlew build. 改为使用该test任务。

gradlew test --debug-jvm

在 Gradle 5.5.1 文档中: https ://docs.gradle.org/current/userguide/java_testing.html#sec:debugging_java_tests


推荐阅读