简体   繁体   English

Junit测试在Eclipse中运行但是没有使用`gradle test`

[英]Junit test run in Eclipse but fails with `gradle test`

I'm using Spring Boot 2 and I'm trying to do an integration test. 我正在使用Spring Boot 2,我正在尝试进行集成测试。 I configured a custom application.properties this way: 我以这种方式配置了自定义application.properties

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

File is under src/test/java/###/$$$/application-integrationtest.properties 文件位于src/test/java/###/$$$/application-integrationtest.properties

Running Junit under Eclipse works fine, but if I try gradle test , I get: 在Eclipse下运行Junit工作正常,但如果我尝试gradle test ,我得到:

java.io.FileNotFoundException: class path resource [###/$$$/application-integrationtest.properties] cannot be opened because it does not exist java.io.FileNotFoundException:无法打开类路径资源[### / $$$ / application-integrationtest.properties],因为它不存在

What's the deal? 这是怎么回事?

Ok, I put my property file under src/test/resources and added the folder to the build path in Eclipse. 好的,我将我的属性文件放在src/test/resources ,并将该文件夹添加到Eclipse中的构建路径中。

PS: my previous answer was wrong. PS:我之前的回答是错误的。 If I name the file application.properties, the default one has the precedence and it's loaded instead of the test one. 如果我将文件命名为application.properties,则默认值为优先级并且已加载而不是测试版。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM