You can set the spring profile by supplying -Dspring.profiles.active=<env>
For java files in source(src) directory, you can use by
System.getProperty("spring.profiles.active")
For java files in test directory you can supply
SPRING_PROFILES_ACTIVE
to <env>
OR
Since, "environment", "jvmArgs" and "systemProperties" are ignored for the "test" task. In root build.gradle
add a task to set jvm property and environment variable.
test {
def profile = System.properties["spring.profiles.active"]
systemProperty "spring.profiles.active",profile
environment "SPRING.PROFILES_ACTIVE", profile
println "Running ${project} tests with profile: ${profile}"
}