This repository is to demonstrate feature toggle functional testing (developer's integration testing) with Spring Boot. Spring boot and dependency injection is used in this repository, still the code can be ported to projects using no frameworks or other frameworks.
- Java JDK Version: 21
- Apache Maven Version: 3.9.9
- Gradle Version: 8
- Git Client: Any latest version
- Integrated Development Environment: Any version of IntelliJ Idea or Eclipse
Feature Toggle Integration Testing with Spring Boot
Note: For maven users on Windows, please use mvnw.cmd instead of ./mvnw in the following commands Note: For gradle users on Windows, please use gradlew.bat instead of ./gradlew in the following commands
./mvnw clean install
To generate html reports
./mvnw surefire-report:report-only surefire-report:failsafe-report-only
./gradlew clean build
With feature toggled off (default behaviour)
./mvnw spring-boot:run
With feature toggled on
./mvnw spring-boot:run -Dspring-boot.run.jvmArguments="-Dfeature-flags.enable-conditional-api=true"
With feature toggle integration test configuration
./mvnw clean compile test-compile exec:java@run-local-ft -Dfeature-flags.enable-conditional-api=true
With feature toggled off (default behaviour)
./gradlew bootRun
With feature toggled on
./gradlew runLocal -Dfeature-flags.enable-conditional-api=true
With feature toggle integration test configuration
./gradlew runLocalFt -Dfeature-flags.enable-conditional-api=true
http://localhost:8080/feature_toggle
Generate the jar file and start the application
./mvnw clean install -DskipUnitTests=true -DskipIntTests=true -DskipFtIntTests=true
With feature toggled off (default behaviour)
java -jar target/feature-toggle-testing-with-spring-boot-0.0.1-SNAPSHOT.jar
With feature toggled on
java -Dfeature-flags.enable-conditional-api=true -jar target/feature-toggle-testing-with-spring-boot-0.0.1-SNAPSHOT.jar
./gradlew clean build -x test -x integrationTest -x ftIntegrationTest
With feature toggled off (default behaviour)
java -jar build/libs/feature-toggle-testing-with-spring-boot-0.0.1-SNAPSHOT.jar
With feature toggled on
java -Dfeature-flags.enable-conditional-api=true -jar build/libs/feature-toggle-testing-with-spring-boot-0.0.1-SNAPSHOT.jar
http://localhost:8080/feature_toggle
For production environments, the feature flags will be enabled or disabled using environment variables. This will be a convenient way to toggle features using environment variable and restart the application with zero downtime and without the need to redeploy the application.
With spring boot feature-flags.enable-conditional-api
property is represented by FEATURE_FLAGS_ENABLE_CONDITIONAL_API
environment variable (i.e replace all '-' and '.' with '_') or FEATURE_ENABLE_CONDITIONAL_API
as mapped in application.yml
Set the environment variable
export FEATURE_FLAGS_ENABLE_CONDITIONAL_API=true
Start the application using java
java -jar target/feature-toggle-testing-with-spring-boot-0.0.1-SNAPSHOT.jar
or
java -jar build/libs/feature-toggle-testing-with-spring-boot-0.0.1-SNAPSHOT.jar
./mvnw help:effective-pom
or
./gradlew dependencyManagement
./mvnw dependency:tree
or
./gradlew dependencies