1

We are using cucumber + selenium to facilitate e2e tests. We are using following dependencies to leverage on spring dependency injection.

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-spring</artifactId>
    <version>6.8.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>5.2.6.RELEASE</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>5.2.6.RELEASE</version>
    <scope>provided</scope>
</dependency>

Then we configure spring context using these two classes

@ContextConfiguration(classes = SpringContextConfig.class)
@CucumberContextConfiguration
public class CucumberSpringConfiguration {
}
@PropertySource("application.properties")
@ComponentScan("com.example.e2e")
public class SpringContextConfig {
}

As we can se we properties source is defined explicitly pointing to a given file. Is there a way to achieve the "magic" that Spring Boot does with profiles and properties files?

For example I would expect spring when specifying -Dspring.profiles.active=dev to merge application-dev.properties with application.properties and giving the final context properties.

julew
  • 216
  • 3
  • 14

1 Answers1

0

As we can se we properties source is defined explicitly pointing to a given file. Is there a way to achieve the "magic" that Spring Boot does with profiles and properties files?

Profile specific configuration files are a Spring Boot feature. So if you are using Spring boot, this should be sufficient to have the active profile picked up:

@SpringBootTest
@CucumberContextConfiguration
public class CucumberSpringConfiguration {
}

From your dependencies however it doesn't look like you are using Spring Boot. There is no other (easy) way to use profile specific configurations files. Consider making your application a Spring Boot application.

M.P. Korstanje
  • 10,426
  • 3
  • 36
  • 58