java—有没有一种方法可以在通过surefire插件执行时排除功能文件包?

cedebl8k  于 2021-06-29  发布在  Java
关注(0)|答案(2)|浏览(420)

所以我必须对cucumber文件进行并行执行,但是有些情况不能并行运行,所以我需要根据包或文件排除它们。
我知道.java文件支持这一点,但是我们有类似的.feature文件吗?
使用junit和surefire插件的cucumber
这是一只鹬

<build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.1</version>
                    <configuration>
                        <parallel>all</parallel>
                        <threadCount>3</threadCount>
                        <excludes>
                            <exclude>You can exclude java files from here but not .feature files</exclude>
                        </excludes>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.aspectj</groupId>
                            <artifactId>aspectjweaver</artifactId>
                            <version>${aspectj.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
mbjcgjjk

mbjcgjjk1#

可以使用中提供的标记排除要素文件 maven-surefire-plugin 配置对象作为系统属性。

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
                <configuration>
                    <parallel>all</parallel>
                    <threadCount>3</threadCount>
                    <!-- Ignore tag System Property below -->
                    <systemPropertyVariables>
                         <cucumber.filter.tags>not @ignore</cucumber.filter.tags>
                    </systemPropertyVariables>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

使用junit平台引擎也允许使用maven excludedgroups(https://github.com/cucumber/cucumber-jvm/tree/main/junit-platform-engine#configuration-(可选)

i7uq4tfw

i7uq4tfw2#

当与cucumber和junit5并行执行场景时,您还可以在特定的资源上同步,而不是将应该串行运行的场景放在单独的测试执行中。
当这样做时,junit平台将以这样一种方式安排测试:不应该并发运行的测试将不会这样做。
https://github.com/cucumber/cucumber-jvm/tree/main/junit-platform-engine#exclusive-资源
要同步特定资源上的方案,必须对方案进行标记,并将此标记Map到特定资源的锁。资源由字符串标识,可以用读写锁或读锁锁定。
例如,以下标记:

Feature: Exclusive resources

 @reads-and-writes-system-properties
 Scenario: first example
   Given this reads and writes system properties
   When it is executed 
   Then it will not be executed concurrently with the second example

 @reads-system-properties
 Scenario: second example
   Given this reads system properties
   When it is executed
   Then it will not be executed concurrently with the first example

使用此配置:
cucumber.execution.exclusive resources.reads and writes system properties.read-write=system\u properties cucucumber.execution.exclusive resources.reads system properties.read=system\u properties
标记为@reads and writes system properties的第一个场景将使用读写锁锁定系统属性,并且不会与使用读锁的第二个场景同时执行。
作为资源价值,你可以定义你自己的资源,
或者使用众所周知的资源,例如:
https://github.com/junit-team/junit5/blob/main/junit-jupiter-api/src/main/java/org/junit/jupiter/api/parallel/resources.java
要使场景独立运行,可以使用 org.junit.platform.engine.support.hierarchical.ExclusiveResource.GLOBAL_KEY https://github.com/junit-team/junit5/blob/ae2a336fe4b371d398da386e8b336cc06329da7d/junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/exclusiveresource.java#l47

相关问题