Using Spring Boot 2.0.0.RC2.
I've written a Configuration class:
@Configuration
@ConditionalOnProperty("launchdarkly.sdkKey")
public class LDClientConfiguration {
@Bean
public LDClientInterface ldClient(LDClientConfigurationProperties props) {
return new LDClient(props.getSdkKey(), props.getLDConfig());
}
}
And a ConfigurationProperties class:
@Component
@ConfigurationProperties(prefix = "launchdarkly")
public class LDClientConfigurationProperties {
private String sdkKey;
// more attributes
public void setSdkKey(String sdkKey) {
this.sdkKey = sdkKey;
}
// more setters
public LDConfig getLDConfig() {
LDConfig.Builder builder = new LDConfig.Builder();
// set builder w/ attributes
return builder.build();
}
}
I'm trying to test this, reading the config from src/test/resources/application-test.yml:
launchdarkly:
sdkKey: <redacted>
I have the following dependencies:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
And junit-platform-surefire-provider is configured in maven-surefire-plugin v2.19.1
I can't seem to figure out the proper annotations for my Test classes to read the config from src/test/resources/application-test.yml.
I've read https://junit.org/junit5/docs/current/user-guide but still can't seem to get the annotations correct. Any help would be appreciated.
edit: test class
@SpringJUnitConfig(SpringBootContextLoader.class)
public class LDClientConfigurationPropertiesTest {
@Autowired
private LDClientConfigurationProperties props;
@Test
public void test() {
LDConfig config = props.getLDConfig();
assertThat(config, notNullValue());
}
}
If I annotate the class with @ExtendWith(SpringExtension.class)
and @SpringBootTest
then it tries to load com/company/spring/launchdarkly/LDClientConfigurationTest-context.xml
and then com/company/spring/launchdarkly/LDClientConfigurationTestContext.groovy
but doesn't look for a yml file.
getSdkKey()
getter that you are calling inLDClientConfiguration.ldClient()
doesn't exist. Did you just omit it here or is it absent in your actual code, too? – anothernode