Maven surefire Testng提供程序运行JUnit测试,但不报告结果 [英] Maven surefire testng provider runs JUnit tests, but doesn't report results

查看:178
本文介绍了Maven surefire Testng提供程序运行JUnit测试,但不报告结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我们同时具有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 */,对于集成为IT /* IT使用Test),这使我能够更好地控制surefire和故障安全. /p>

要么使用命名约定将测试包括在surefire插件的默认行为中,要么将插件配置为运行特定的测试并收集所需的数据.

In my project, we have both TestNG and JUnit (actually Spock) tests. So we need to run both, and get results from both. With surefire providers it seemd quite easy, so we did this:

        <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>

However, after some time I found out that junit tests are run twice. This is not good, because we have a lot of tests, and I'd like to limit the time they are running.

After a little research I found out that surefire-testng provider runs both TestNG and JUnit tests. So again it seemed simple - I removed surefire-junit47 provider.

Well, this was not a good solution either, because it turned out testng provider runs junit tests, but doesn't provide results in target/surefire-reports/TEST*.xml. I found only TestNG results there.

Is there any solution to have tests run only once, and results reported?

解决方案

I use surefire-testng to run junit tests, but don't have any testng tests in the same run.

I extract the reports using:

**/surefire-reports/*.xml

You can configure surefire-testng to include or exclude any tests, perhaps you can exclude the junit tests by pattern, then have the junit47 provider run those?

surefire-reports can also be configured to collect junit and/or testng reports.

Later junit tests use annotations rather than naming conventions. testng seems to recognise this, but default behaviour of surefire-reports seems to be only collect data by naming convention.

I still use naming conventions as well as annotations in my junit tests (Test*/Test for unit and IT/*IT for integration), which allows me to control surefire and failsafe better.

Either utilise naming conventions to include tests in surefire plugins default behaviour, or configure the plugins to run specific tests and collect the data you want.

这篇关于Maven surefire Testng提供程序运行JUnit测试,但不报告结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆