1

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?

1

2 Answers 2

2

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() { } } 
Sign up to request clarification or add additional context in comments.

Comments

1

This works after I put application.properties file in the test directory

src/test/resources/application.properties 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.