【问题标题】:How to configure spock framework in Springboot?如何在 Spring Boot 中配置 spock 框架?
【发布时间】:2021-02-19 02:45:27
【问题描述】:

我想在我的 Spring Boot 应用程序中使用 Spock 进行测试。 我的应用程序正在使用 java,但我希望 Spock 使用 groovy 进行测试。

我在 pom.xml 文件中添加了这两个依赖项。

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.spockframework/spock-core -->
        <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-core</artifactId>
            <version>${spock.version}</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.spockframework/spock-spring -->
        <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-spring</artifactId>
            <version>${spock.version}</version>
            <scope>test</scope>
        </dependency>


我错过了什么吗?

【问题讨论】:

  • 看看github.com/spockframework/spock-example 项目,你仍然缺少gmaven 编译器。你想用什么版本的 spock 和 spring?
  • @LeonardBrünings Spring boot 版本 2.3.1.RELEASE 和 spock 版本 2.0-M3-groovy-2.5 和 gmavenplus-plugin 1.6,如 spock 示例中所述。我正在使用 intellij Idea,但无法运行测试。 class HelloSpec extends Specification { def "maximum"(){ expect: Math.max(1,2)==2 } }
  • 请不要在 cmets 中发布代码,而是更新问题。我还建议您在 GitHub 上发布您的 MCVE 以使问题可重现。您似乎是第一次这样做,因此您的问题有很多可能的根本原因。分析胜过猜测,所以请向我们展示的不仅仅是一些 Maven 和 Spock sn-ps。谢谢你。 ??????

标签: spring spring-boot testing pom.xml spock


【解决方案1】:

您缺少编译您的 groovy 源代码的 gmavenplus-plugin

        <plugin>
            <groupId>org.codehaus.gmavenplus</groupId>
            <artifactId>gmavenplus-plugin</artifactId>
            <version>1.12.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>addTestSources</goal>
                        <goal>compileTests</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-25
    • 2018-10-07
    • 2015-08-06
    • 1970-01-01
    • 2022-01-19
    • 2014-07-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多