Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle doesn't pass System properties to test classes

I am using Selenium and Spock for testing my application. Running tests that need System properties from Maven or my IDE works like a charm, but Gradle is getting null values.

@Shared
private int waitTimeout = System.getProperty("waitTimeout", "10").toInteger()

@Shared
protected String apolloURL = System.getProperty("apolloURL")

Maybe I am doing something wrong?

like image 248
IowA Avatar asked Jul 25 '13 07:07

IowA


People also ask

How do I pass system properties to Gradle build?

Using the -D command-line option, you can pass a system property to the JVM which runs Gradle. The -D option of the gradle command has the same effect as the -D option of the java command. You can also set system properties in gradle. properties files with the prefix systemProp.

Does Gradle run tests in parallel by default?

Parallel execution Yet Gradle will only run one task at a time by default, regardless of the project structure (this will be improved soon). By using the --parallel switch, you can force Gradle to execute tasks in parallel as long as those tasks are in different projects.

How do I run test cases in Gradle?

Run Gradle testsIn your Gradle project, in the editor, create or select a test to run. From the context menu, select Run <test name>. icon in the left gutter. If you selected the Choose per test option, IntelliJ IDEA displays both Gradle and JUnit test runners for each test in the editor.


1 Answers

See Test task type in the Gradle Build Language Reference.

test {
    systemProperty "waitTimeout", "20"
    systemProperty "apolloURL", "..."
}
like image 86
Peter Niederwieser Avatar answered Nov 09 '22 12:11

Peter Niederwieser