加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 通过Maven使用Junit Categories运行Cucumber测试

发布时间:2020-12-15 00:54:08 所属栏目:Java 来源:网络整理
导读:我有一个包含多个模块和一个公共父模块的maven项目.在这个项目中,有一些单元测试与Junit以及surefire一起运行,以及BDD Cucumber集成测试.我想运行两个单独的作业,一个用于运行所有单元测试,另一个用于运行BDD / Integration测试.为了做到这一点,我使用Junit
我有一个包含多个模块和一个公共父模块的maven项目.在这个项目中,有一些单元测试与Junit以及surefire一起运行,以及BDD Cucumber集成测试.我想运行两个单独的作业,一个用于运行所有单元测试,另一个用于运行BDD / Integration测试.为了做到这一点,我使用Junit类注释注释了我的BDD运行器类,如下所示:
@RunWith(Cucumber.class)
@CucumberOptions(
                tags = { "@ATagToBeRun","~@ATagNotToBeRun","~@ToBeImplemented" },dryRun = false,strict = true,features = "src/test/resources/cucumber/testing",glue = { "com.some.company.test","com.some.company.another.test"})
@Category(value = IntegrationTest.class)
public class FlowExecutionPojoTest {
}

我在父pom中创建了一个Maven配置文件,它使用maven-surefire-plugin功能,旨在根据组过滤测试.这是我的maven配置:

<dependencies>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.4</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.4</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-spring</artifactId>
            <version>1.2.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm-deps</artifactId>
            <version>1.0.5</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <profile>
        <id>testJewels</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <modules>
            <module>../my-module</module>
        </modules>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.19.1</version>
                    <configuration>
                        <groups>com.some.company.IntegrationTest</groups>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

我所期望的是,当我运行mvn test -PtestJewels时,使用< groups>中包含的类别注释的类.标签应该执行.实际上,没有任何带注释的类被执行.

一个有趣的注意事项是,当我使用maven-surefire-plugin版本2.18时,这有效,但是从版本2.18.1开始,它没有.根据页面底部的documentation,版本2.18.1中有关于继承类别的更改但在我的情况下它们是在

解决方法

我发现在cucumber-jvm存储库中实际上有一个 pull request来修复这个特定的问题.问题是由于当Junit根据@Category注释过滤测试运行器类时,它也会检查所有子类.在运行.feature文件的黄瓜测试的情况下,也检查表示.feature文件的所有类(黄瓜转换FeatureRunner类的实例中的每个.feature文件).由于FeatureRunner类上不存在注释,因此测试将被过滤掉而不会运行. (在版本2.18.1之前,maven-surefire-plugin没有检查子类的注释,因此这不是问题.

对于我在上面描述的特定设置(适用于特定模块中运行所有BDD测试)的解决方法是覆盖< groups>子模块中的配置,如下所示:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <groups combine.self="override"></groups>
            </configuration>
        </plugin>
    </plugins>
</build>

这显然不适用于不同的设置,因此非常不幸的是黄瓜团队还没有合并我上面提到的PR.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读