Reputation: 5242
I got a JUnit test that relies upon a Java SystemProperty (more precisely the library used in it relies on it). I want to start the JUnit test from IntelliJ. Therefore I edited the run configuration and added VM options like "-DpropertyName=value". IntelliJ then starts gradle with something like this:
gradle cleanTest test --tests com.example.Test -DpropertyName=value
When I check from my Test with System.getProperty() / getProperties() the property was not passed and thus is null.
How can i pass the properties to the JunitTest?
Upvotes: 7
Views: 3571
Reputation: 5242
As it turns out, IntelliJ can only pass those JVM options to the JVM gradle runs in and gradle will not pass those to the tests. To specify a property for the JVM that will run the tests, either edit the build.gradle
file and add:
test {
systemProperty 'propertyName', 'value'
}
or, instead, add
test.jvmArgs System.getProperty("test.jvmArgs").split(" ")
to the build.gradle
file and modify your run configuration VM options to be something like
-Dtest.jvmArgs="-DpropertyName=value -Dprop2=value2"
Upvotes: 10