I am using SpringBoot for latest development.Profile based configuration we have so there are 3 files are there
application-{env}.properties, env means dev,stage and prod
When I run the project locally in eclipse using -Dspring.profiles.active=dev
run configuration it is picking configurations from application-dev.properties. But If I try to run a jUnit, it is expecting application.properties otherwise throwing error.I put a application.properties it is working fine.Please tell me how to configure JUnit with profile based so that which will pick application-dev.properties.Please give your input on this, thanks in advance.
@SpringBootTest
@RunWith(SpringRunner.class)
public class ProcessingServiceTest {
@Test
public void testlet2MeIn() throws Exception{
}
}
Did you try setProperty
?
@SpringBootTest
@RunWith(SpringRunner.class)
public class ProcessingServiceTest {
public ProcessingServiceTest(){
System.setProperty("spring.profiles.active","dev");
}
@Test
public void testlet2MeIn() throws Exception{
}
}
you can specify the properties files using @TestPropertySource
and specify which file should be used to load properties for tests
@TestPropertySource(locations = "classpath:application-dev.properties")
Or the simplest way is to use this on your test class @ActiveProfiles("dev")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.