【问题标题】:Running Spock tests in parallel并行运行 Spock 测试
【发布时间】:2017-06-13 08:45:04
【问题描述】:

我的 E2E 测试运行得很慢(25 分钟),因为它们会调用一堆服务并等待一些数据填充到数据库中。我想同时运行它。我正在使用以下maven-failsafe-plugin 设置:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>${plugin.failsave.version}</version>
    <executions>
        <execution>
            <id>run-integration-tests</id>
            <phase>integration-test</phase>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
</plugin>

我的测试看起来像这样(如果需要,可以提供更多信息):

@Stepwise
@DataJpaTest
@ContextConfiguration(classes = SomeControllerITConfig)
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
class SomeControllerIT extends Specification {
    // some variables definition

    def "test1":
        // some test

    def "test2":
        // some test

    // some more tests
}

我尝试将threadCount 属性与parallelforkCount 一起使用,但对我没有任何作用。我还尝试在 maven-failsafe-plugin 依赖项中强制以下依赖项:

<dependency>
      <groupId>org.apache.maven.surefire</groupId>
      <artifactId>surefire-junit47</artifactId>
      <version>2.16</version>
</dependency>

提前致谢!

【问题讨论】:

    标签: spring integration-testing spock e2e-testing maven-failsafe-plugin


    【解决方案1】:

    我在 GitHub 上遇到了以下问题:

    https://github.com/spockframework/spock/issues/691

    如果您也对 Spock 中的并行测试执行感兴趣,请发表评论或发表评论。

    简而言之,我发现了一个启用并行执行的拉取请求,它甚至被合并到其中一个分支中。但是它还没有合并到master中。所以我现在看到的唯一出路是编写我自己的自定义BaseSpecRunner

    【讨论】:

    • 从这个 PR 中可以看出,它与在同一 Spec 中并行执行测试有关。基于类的并行化应该可以正常工作。
    • @jihor 仅在 Gradle 中
    【解决方案2】:

    Spock 团队似乎增加了对并行执行的支持:

    http://spockframework.org/spock/docs/2.0-M4/parallel_execution.html#parallel-execution

    需要 groovy:>3.0.6

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-28
      • 2014-08-02
      • 1970-01-01
      • 1970-01-01
      • 2016-12-12
      • 1970-01-01
      • 2019-12-01
      相关资源
      最近更新 更多