gpt4 book ai didi

java - 如何在 Eclipse 中调试 maven surefire 测试

转载 作者:行者123 更新时间:2023-11-30 08:52:34 25 4
gpt4 key购买 nike

我正在尝试在 Eclipse 中调试我的 Maven Surefire 测试套件。我正在使用 TestNg 作为测试运行器。我可以从终端运行此命令,然后在 Eclipse 中启动“远程 Java 应用程序”进行调试:

mvn clean test -Dmaven.surefire.debug -Dclass=com.myTests.SampleTestClass

是否可以在 Eclipse 中设置调试配置,以便我可以直接从 Eclipse 进行调试,而无需在终端中运行命令?

这是我在 Pom.xml 中的 maven surefire 设置

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<systemPropertyVariables>
<my_property>${my_property}</my_property>
</systemPropertyVariables>
<properties>
<property>
<name>listener</name>
<value>com.myPackage.TestListener</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>

最佳答案

正如 khmarbaise 已经提到的,抛弃 Maven 部分,只从 Eclipse 本身运行测试。

在选择包含 TestNG 测试的包后,您要使用的组合键是:Alt + Shift + DN

要调试 JUnitTest,请将 N 替换为 T

关于保留当前功能:要将监听器附加到您的 testng 测试套件,请使用 @Listeners-Annotation ,您可以在其中附加多个实现 ITestNGListener 的类来收听您的套件。

请注意,ITestNGListener 只是一个标记接口(interface),没有其他功能。

对于定义的 systemPropertyVariables:您应该能够将它们附加到您的 testng 运行(和调试)配置中。

关于java - 如何在 Eclipse 中调试 maven surefire 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30141933/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com