gpt4 book ai didi

java - Maven surefire testng 提供程序运行 JUnit 测试,但不报告结果

转载 作者:行者123 更新时间:2023-11-29 08:48:23 25 4
gpt4 key购买 nike

在我的项目中,我们同时进行了 TestNG 和 JUnit(实际上是 Spock)测试。所以我们需要同时运行两者,并从两者中获得结果。使用 surefire 提供程序,这似乎很容易,所以我们这样做了:

        <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<threadCount>1</threadCount>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.17</version>
</dependency>
</dependencies>
</plugin>

但是,一段时间后我发现 junit 测试运行了两次。这不好,因为我们有很多测试,我想限制它们运行的​​时间。

经过一些研究,我发现 surefire-testng 提供程序同时运行 TestNG 和 JUnit 测试。所以再次看起来很简单 - 我删除了 surefire-junit47 提供程序。

嗯,这也不是一个好的解决方案,因为事实证明 testng 提供程序运行 junit 测试,但没有在 target/surefire-reports/TEST*.xml 中提供结果。我在那里只找到了 TestNG 结果。

是否有任何解决方案可以让测试只运行一次并报告结果?

最佳答案

我使用 surefire-testng 来运行 junit 测试,但在同一次运行中没有任何 testng 测试。

我使用以下方法提取报告:

**/surefire-reports/*.xml

您可以配置 surefire-testng 以包含或排除任何测试,也许您可​​以按模式排除 junit 测试,然后让 junit47 提供程序运行这些测试?

surefire-reports 也可以配置为收集 junit 和/或 testng 报告。

后来的 junit 测试使用注释而不是命名约定。 testng 似乎认识到这一点,但 surefire-reports 的默认行为似乎只是通过命名约定收集数据。

我仍然在我的 junit 测试中使用命名约定和注释(Test*/Test for unit and IT/*IT for integration),这让我可以更好地控制 surefire 和 failsafe。

要么利用命名约定将测试包含在 surefire 插件的默认行为中,要么配置插件以运行特定测试并收集您想要的数据。

关于java - Maven surefire testng 提供程序运行 JUnit 测试,但不报告结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23959039/

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