Junit test run in Eclipse but fails with `gradle t

2019-08-17 08:12发布

问题:

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 = { "###.$$$" })

File is under src/test/java/###/$$$/application-integrationtest.properties

Running Junit under Eclipse works fine, but if I try gradle test, I get:

java.io.FileNotFoundException: class path resource [###/$$$/application-integrationtest.properties] cannot be opened because it does not exist

What's the deal?

回答1:

Ok, I put my property file under src/test/resources and added the folder to the build path in Eclipse.

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.