【问题标题】:Both data.sql file is being used from resources and test resources folder when a @DataJpaTest Junit is being run运行 @DataJpaTest Junit 时,正在使用资源和测试资源文件夹中的两个 data.sql 文件
【发布时间】:2019-01-05 15:04:52
【问题描述】:

在运行带注释的 @DataJpaTest Junit 时,正在使用资源和测试资源文件夹中的 data.sql 文件。

当执行带有@DataJpaTest 注释的Junit 测试时,如何告诉spring boot 只使用测试资源文件夹中的data.sql?

谢谢。

【问题讨论】:

  • 请提供您的单元测试

标签: java spring-boot junit spring-boot-test


【解决方案1】:

尝试:

@Sql(scripts={"classpath:data.sql"})

【讨论】:

    【解决方案2】:
    @shodz... try this.
    
        @SqlGroup({
            @Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:beforeTestRun.sql"),
            @Sql(executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, scripts = "classpath:afterTestRun.sql")
    
                  })
    

    【讨论】:

    • 谢谢。我会试试这个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-28
    • 1970-01-01
    • 2012-05-19
    相关资源
    最近更新 更多