【问题标题】:Junit test run in Eclipse but fails with `gradle test`Junit 测试在 Eclipse 中运行,但因“gradle test”而失败
【发布时间】:2019-03-22 10:31:59
【问题描述】:

我正在使用 Spring Boot 2,并且正在尝试进行集成测试。 我这样配置了一个自定义的application.properties

@TestPropertySource(
    locations = "classpath:###/$$$/application-integrationtest.properties"
)
@ComponentScan(basePackages = { "###.$$$" })

文件在src/test/java/###/$$$/application-integrationtest.properties

在 Eclipse 下运行 Junit 工作正常,但如果我尝试 gradle test,我会得到:

java.io.FileNotFoundException:类路径资源 [###/$$$/application-integrationtest.properties] 打不开 因为它不存在

怎么了?

【问题讨论】:

  • 属性文件不会进入 src/test/java。这适用于 java 源文件。他们去 src/test/resources。

标签: java spring spring-boot testing integration-testing


【解决方案1】:

好的,我将我的属性文件放在src/test/resources 下,并将该文件夹添加到Eclipse 中的构建路径中。

PS:我之前的回答是错误的。如果我将文件命名为 application.properties,则默认的具有优先级,并且会加载它而不是测试的。

【讨论】:

    猜你喜欢
    • 2021-10-31
    • 1970-01-01
    • 1970-01-01
    • 2012-05-27
    • 2019-05-01
    • 2011-07-23
    • 1970-01-01
    • 2016-03-22
    • 2017-05-15
    相关资源
    最近更新 更多