Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass JVM system properties on to my tests?

Tags:

gradle

geb

I have the following task

task testGeb(type:Test) {
   jvmArgs '-Dgeb.driver=firefox'
   include "geb/**/*.class"
   testReportDir = new File(testReportDir, "gebtests")
}

The system property doesn't appear to make it to the Geb tests, as Geb does not spawn Firefox to run the tests. When I set the same system property in Eclipse and run the tests, everything works fine.

like image 380
Ray Nicholus Avatar asked Apr 12 '11 20:04

Ray Nicholus


People also ask

How do you pass properties in Java?

-D is used to set properties. Properties are strings that can be read inside code and can be specified to the JVM in multiple ways, including this parameter. This parameter can be specified multiple times: one for each parameter/value combination that you want to pass to the program.

What is JVM system property?

System properties contain information to configure the JVM and its environment. Some system properties are particularly relevant for JVMs in a CICS® environment. Specify JVM system properties in the JVM profile.


2 Answers

Try using system properties:

test {
   systemProperties['geb.driver'] = 'firefox'
   include "geb/**/*.class"
   testReportDir = new File(testReportDir, "gebtests")
}
like image 103
Nikita Skvortsov Avatar answered Oct 14 '22 15:10

Nikita Skvortsov


You can also directly set the system property in the task:

task testGeb(type:Test) {
    System.setProperty('geb.driver', 'firefox')}

(the solution above will also work for task type different from Test)

or if you would like to be able to pass different properties from the command line, you can include a more flexible solution in the task definition:

task testGeb(type:Test) {
    jvmArgs project.gradle.startParameter.systemPropertiesArgs.entrySet().collect{"-D${it.key}=${it.value}"}
}

and then you can run: ./gradlew testGeb -D[anyArg]=[anyValue], in your case: ./gradlew testGeb -Dgeb.driver=firefox

like image 35
OlgaMaciaszek Avatar answered Oct 14 '22 14:10

OlgaMaciaszek