I have below setup
- Springboot v3.x
- Cucumber v7.x
- Junit v5.x
- Maven v3.x
I am able to run cucumber test with below configuration to test SpringBoot Application running locally using maven failsafe plugin.
Note: The configuration uses @SpringBootTest annotation to start the SubjectUnderTest(SUT) before the running the Test.
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.example.bdd.stepdefs")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME,
value = "pretty," +
"html:target/tests-reports/report.html," +
"json:target/tests-reports/report.json," +
"junit:target/tests-reports/cucumber-junit.xml,")
@CucumberContextConfiguration
@ActiveProfiles("local")
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class FunctionalIT {
}
My Requirements:
- Reuse the same cucumber tests to validate the springboot application started using the @SpringBootTest during the maven integration test, as well as testing the deployed application on remote environments (e.g. qa, prod)
- Leverage Spring application-env.properties files and profiles for the environment specific configuration.
- Only start the minimum required Spring ApplicationContext depending on the test to be run against the local app (@SpringBootTest) vs remote app (No @SpringBootTest annotation).
- Specify the active profile as needed e.g.
-Dspring.profiles.active=localor-Dspring.profile.active=qa. And only that profile should be used by the Spring.
I tried few options without much success so far, I faced below issues:
- Tried createing another test class for remote environments without
@SpringBootTestannotation, but@CucumberContextConfigurationis only allowed on single class. - If I separate all cucumber config in its own class, the junit is not running the cucumber tests. Aparently
@CucumberContextConfigurationneeds to be applied on@SpringBootTestor@ContextConfigurationonly.
Any idea how to get the setup working for the above requirements ?
I solved the problem with the below changes.
pom.xmlNow for running
mvn clean verifyruns unit tests and ComponentIT by default (for local and CI environment)mvn clean verify -P acceptance-tests -Denv=qaruns AcceptanceIT tests onqaenvironment, like wise-Denv=stageor-Denv=prodto run tests against thestageandprodenvironments respectively.