Junit测试在Eclipse中运行,但由于"gradle test"而失败 [英] Junit test run in Eclipse but fails with `gradle test`
问题描述
我正在使用Spring Boot 2,并且正在尝试进行集成测试.
我通过以下方式配置了自定义application.properties
:
I'm using Spring Boot 2 and I'm trying to do an integration test.
I configured a custom application.properties
this way:
@TestPropertySource(
locations = "classpath:###/$$$/application-integrationtest.properties"
)
@ComponentScan(basePackages = { "###.$$$" })
文件在src/test/java/###/$$$/application-integrationtest.properties
在Eclipse下运行Junit可以正常工作,但是如果我尝试gradle test
,则会得到:
Running Junit under Eclipse works fine, but if I try gradle test
, I get:
java.io.FileNotFoundException:类路径资源 [###/$$$/application-integrationtest.properties]无法打开 因为它不存在
java.io.FileNotFoundException: class path resource [###/$$$/application-integrationtest.properties] cannot be opened because it does not exist
怎么了?
推荐答案
好吧,我将属性文件放在src/test/resources
下,并将该文件夹添加到Eclipse中的构建路径.
Ok, I put my property file under src/test/resources
and added the folder to the build path in Eclipse.
PS:我以前的回答是错误的.如果我将文件命名为application.properties,则默认文件具有优先级,并且已加载而不是测试文件.
PS: my previous answer was wrong. If I name the file application.properties, the default one has the precedence and it's loaded instead of the test one.
这篇关于Junit测试在Eclipse中运行,但由于"gradle test"而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!