I'm not able to make my unit test to read application.yml. I have followed the answer as the url below but it's still not working.
Spring Boot properties in 'application.yml' not loading from JUnit Test
Appreciate if somebody can help. Thanks.
My code as below:
Application.java
@SpringBootApplication
@ImportResource("classpath:app-config.xml")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
TestTokenGenerator.java
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=Application.class, initializers=ConfigFileApplicationContextInitializer.class)
@ContextConfiguration(locations={"classpath:app-config-test.xml"})
public class TestTokenGenerator {
private static final Logger log = LoggerFactory.getLogger(TestTokenGenerator.class);
@Value("${test}")
private String testB;
@Test
public void testGenerate() throws UnrecoverableKeyException, KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException{
log.info(testB);
log.info(tokenGenerator.generateToken());
}
application.yml
test: "123123"