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

标签 java unit-testing maven junit testng

在我的项目中,我们同时进行了 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/

相关文章:

unit-testing - 您如何使依赖于扩展方法的方法可测试?

java - 如何使用 Mockito 验证未使用任何参数组合调用的模拟方法

java - 错误 :Invalid use of argument matchers! 预计有 0 个匹配器,已记录 1 个

Android 应用程序对 android 库项目的引用在 Maven-> 更新项目后中断

java - Maven:将本地依赖添加到jar

java - 枚举 : get the keys list

java - 如何填写类(class)中的所有字段?

java - 如何从另一个java程序运行一个java程序?

java - String X, Y 之间的区别;和字符串 X,字符串 Y;

java - testng在linux maven命令行上运行