Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run gradle task with Spring Profiles (Integration tests)

Need to run tests via gradle with spring profiles.

gradle clean build

I've added task:

task beforeTest() {
    doLast {
      System.setProperty("spring.profiles.active", "DEV")
    }
}

test.dependsOn beforeTest

And my test definition is:

@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles("TestProfile")
public class SomeTest {

But this construction doesn't work for me.

Gradle runs tests.

like image 569
yazabara Avatar asked May 30 '17 08:05

yazabara


1 Answers

I think you are wanting to set a system property in the runtime/test JVM but you are incorrectly setting a system property in the build-time JVM (ie the Gradle daemon).

See Test.systemProperty(String, Object)

Eg:

test {
    systemProperty 'spring.profiles.active', 'DEV'
}

... and another note on your attempt. Please note that tasks have a doFirst and a doLast method so you wouldn't need a separate task for what you were attempting.

like image 112
lance-java Avatar answered Sep 19 '22 15:09

lance-java