I have a TestBase class that is extended by all test classes. This class runs locally from IntelliJ if the @PropertySource("classpath:/test.properties")
is used on it it runs properly in the CI pipeline, but if I want to run locally a test (Intellij, click, Run) then I have to replace this with @TestPropertySource("classpath:/test.properties")
(Both do not work, the CI does not work with only TestPropertySource
local does not work from IntelliJ as mentioned if PropertySource
is used)
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@ExtendWith(SpringExtension.class)
@TestConfiguration
@PropertySource("classpath:/test.properties") // This is the problematic line
@EnableConfigurationProperties
@ContextConfiguration(classes = {...})
@ComponentScan(basePackageClasses = ...)
@Slf4j
public class TestBase {
...
}
Currently the only workaround we have is to temporarily replace this while developing. We tried to use ContextConfiguration
class with ConditionalOnExpression
annotation etc.. Nothing works.
The decision which one to use could be as simple as to check a System or Environment variable exists or not.
Can someone help me how can I have this work on both local and CI env by loading one or the other way the same configuration file?
1