2

I have my custom properties defined in application.properties file located in src/main/resources folder. I want to add test cases for my application hence I added application-integration.properties in the src/test/resources folder as mentioned here. The test case is added as below

@SpringBootTest
@ActiveProfiles("integration")
public class ServiceATest {

    @Value("${app.api.url}")
    private String apiUrl;

    @Test
    public void testService() {
        Assertions.assertNotNull(apiUrl);
    }
}

The above test case fails. I do not understand why the properties are not read from application-integration.properties and nor from application.properties. The latter is not expected though still just for the understanding. Any idea what could be going wrong?

Thanks.

Andy Dufresne
  • 6,022
  • 7
  • 63
  • 113
  • Where does the problem occur - in Eclipse, on the command line with 'mvn'? – blafoo Feb 09 '22 at 08:32
  • On running the test class from Intellij Community Edition – Andy Dufresne Feb 09 '22 at 08:48
  • Did you define some kind of configuration in Intellij using `-Dspring.profiles.active=xxx`? Do the test fail using mvn on the command line, too? – blafoo Feb 09 '22 at 08:57
  • I tried setting an environment variable when executing the above test class as `-Dspring.profiles.active=integration` but the test case still failed. Maven test run is taking time since there are other test classes that are failing. will check and revert back – Andy Dufresne Feb 09 '22 at 09:06
  • Perhaps your integration config doesn’t contain all the properties. If it doesn’t it will grab them from your generic application.properties – Daniel Jacob Feb 10 '22 at 13:49
  • @DanielJacob - the problem is certainly to do with test config. It doesn't seem to be reading any properties files – Andy Dufresne Feb 11 '22 at 06:06

0 Answers0