How to add Java system property at runtime with JUnit Test Execution

I need to define a system property for my JUnit tests. I tried various steps to pass a name / value pair in gradle. (I tried Milestone-3 and 4). None of these approaches worked:

  • systemProp.foo = line definition in gradle.properties file
  • pass -Dfoo = bar on the command line
  • pass -PsystemProp.foo = bar on the command line

I do not see the additional properties from the gradle properties, although I'm not sure what I should. But more importantly, I dropped System.properties in the static initializer, but the property is not there. I need to pass System properties to current tests to tell them which environment they are working in (local, Jenkins, etc.).

+6
source share
2 answers

Sorry to answer my own question. Just stumbled upon a solution here :

test {systemProperties = System.properties}

+9
source

You can also define individual properties as follows:

test { systemProperty "file", "test.story" } 

(From this answer )

+1
source

Source: https://habr.com/ru/post/893897/


All Articles