I have a Spring Boot 1.4.3 project. In the folder test/resourcesI have two properties files, say,
a-test.propertiesand b-test.properties.
The validation class is annotated as follows:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(locations = "classpath:a-test.properties")
However, I see in my test that the properties are being loaded from b-test.properties(I checked this with simple print output).
Why? How can I prevent this?
Example extracted from my test
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(locations = "classpath:base-test.properties", inheritProperties=false)
public class EmailServiceContextBasedTest {
@SpyBean
public JavaMailSender javaMailSender;
@Before
public void setUp() throws Exception {
System.out.println(
((JavaMailSenderImpl)javaMailSender).getPassword()
);
System.out.println(
((JavaMailSenderImpl)javaMailSender).getJavaMailProperties()
);
}
@Test
public void test() throws Exception {
}
}
where a-test.properties:
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=email@gmail.com
spring.mail.password=password
spring.mail.properties.mail.smtp.auth=false
spring.mail.properties.mail.smtp.starttls.enable=false
and b-test.properties
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=myemail@gmail.com
spring.mail.password=myPassword
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
source
share