Reputation: 453
I am using the following annotations in my spring boot testing files
@RunWith(SpringRunner.class) // tells JUnit to run using Spring’s testing support.
@SpringBootTest // is saying “bootstrap with Spring Boot’s support” (e.g. load application.properties and give me all the Spring Boot goodness)
@AutoConfigureMockMvc
When I test rest controllers, it will show java.lang.IllegalStateException: Failed to load ApplicationContext
.
I checked the log, and this is caused by connection issues with JMS and database. For my rest controllers testing, I do not need any of them. But their configuration is defined in the application.properties file and it will be loaded in the SpringBootTest, how can I use a different application.properties file for the testing purpose?
Upvotes: 1
Views: 2092
Reputation: 453
This works after I put application.properties file in the test directory
src/test/resources/application.properties
Upvotes: 1
Reputation: 1248
we can use @TestPropertySource or @PropertySource to load the properties file.
@RunWith(SpringRunner.class)
@SpringBootTest
@TestPropertySource("classpath:properties.yml")
@ActiveProfiles("test")
public class CartLoadApplicationTests {
@Test
public void contextLoads() {
}
}
Upvotes: 2