I am trying to pass arguments to the JVM when running JUnit 5 tests.
I have a properties file which defines the locations of a bunch of input files. I wanted to pass the root folder as a JVM argument so it’s not hardcoded in my properties file. I was able to accomplish the same when I execute the program by using the application plugin and setting the applicationDefaultJvmArgs variable, but when I run the tests the variable is not set and all my tests fail. I do not want the test to depend on the program execution. I want to be able to run them independently.
I tried 2 different approaches but regardless the jvmArgs are not set correctly and my tests are failing.
Here’s what I’ve tried:
approach 1
junitPlatform {
enableStandardTestTask = true
}
task runJunitPlatform (type: JavaExec) {
jvmArgs '-Droot.folder=c:/projects/scagABM'
}
test.dependsOn runJunitPlatform
After doing the above, I do not see the test task running so the jvm args are not set and the tests fail
approach 2
afterEvaluate {
def junitPlatformTestTask = tasks.getByName('junitPlatformTest')
junitPlatformTestTask.systemProperty 'org.gradle.jvmArgs', '-Droot.folder=c:/projects/scagABM'
}
For setting the jvmArgs I tried both what is above and the following
junitPlatformTestTask.jvmArgs '-Droot.folder=c:/projects/scagABM'
but again nothing…
Am I missing something here? Any suggestions of how I can set the jvmArgs from the junit platform tests?