我正在尝试在 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 + D, N
要调试 JUnitTests,请将 N 替换为 T
至于保留当前功能:要将监听器附加到您的 testng 测试套件,请使用 @Listeners
-Annotation ,您可以在其中附加多个实现 ITestNGListener
的类来监听您的套件。
请注意,ITestNGListener 只是一个标记接口(interface),没有其他功能。
对于定义的systemPropertyVariables
:您应该能够将它们附加到您的 testng 运行(和调试)配置中。
关于java - 如何在 Eclipse 中调试 Maven Surefire 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30141933/