0

I have an extremely basic SpringBootTest that I am trying to run (the contextLoads()) test.

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

@SpringBootTest
@ActiveProfiles("test")
public class ApplicationTest {


    @Test
    void contextLoads() {
    }


}

I have a config file application-test.yml under src/test/resources/ with some basic configuration that I'd like to use to test my application with. However even with the simple test above the context isn't loading. I'm using IntelliJ to run my tests - and when I run the unit test with Maven the test just is in a running state but it seems like it's frozen loading the context. The only thing I see is

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.1.RELEASE)

and that it says "Running tests..." and it doesn't resolve. I'm not exactly sure what's wrong here. I've noticed when I remove the @ActiveProfiles annotation that the test fails to run and throws back an exception Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class where it looks like it's trying to get load my actual configuration file and it' cant because I haven't set environment variables that I use in the config file. So How can I get SpringBootTest to pick up on the application-test.yml and proceed with the test?

alex
  • 1,905
  • 26
  • 51
  • https://stackoverflow.com/questions/38711871/load-different-application-yml-in-springboot-test. Please refer to this question and i think the comments to the answer with the 24 upvotes might help you. – Ananya Antony Jun 18 '20 at 07:14
  • So I tried to create a file `application.yml` under `src/test/resources/config/` and I have the same behavior - the test will not run and the context will not start. I even replaced my main configuration file with all my test values and tried to run the test but it will not run. It's very strange because this application runs fine when started like `java -jar` but not with this test. – alex Jun 18 '20 at 14:39
  • So far I've converted my file to a `.properties` file and the context will still not load. – alex Jun 18 '20 at 15:45
  • so I think it's picking up the config file - but for some reason the context still isn't loading – alex Jun 18 '20 at 16:08

0 Answers0