I need to define a system property for my JUnit tests. I\'ve tried various steps to pass the name/value pair into gradle. (I\'ve tried Milestone-3 and 4). None of these app
with android, you can use
android {
...
testOptions {
...
// Encapsulates options for local unit tests.
unitTests {
// By default, local unit tests throw an exception any time the code you are testing tries to access
// Android platform APIs (unless you mock Android dependencies yourself or with a testing
// framework like Mockito). However, you can enable the following property so that the test
// returns either null or zero when accessing platform APIs, rather than throwing an exception.
returnDefaultValues true
// Encapsulates options for controlling how Gradle executes local unit tests. For a list
// of all the options you can specify, read Gradle's reference documentation.
all {
// Sets JVM argument(s) for the test JVM(s).
jvmArgs '-XX:MaxPermSize=256m'
// You can also check the task name to apply options to only the tests you specify.
if (it.name == 'testDebugUnitTest') {
systemProperty 'debug', 'true'
}
...
}
}
}
}
Sorry to answer my own question. Just stumbled upon the solution here:
test { systemProperties = System.properties }
You can also define individual properties like this:
test {
systemProperty "file", "test.story"
}
(From this answer)