Reputation: 387
Is there any way to run JUnit test cases with program arguments, VM arguments and working directory?
I've tried with org.junit.runner.JUnitCore
, but I can't find the way to pass these parameters.
Upvotes: 1
Views: 1960
Reputation: 4840
You can pass system parameters with the -Dproperty=value
Program arguments are just passed at the end of the java command line. However, they will be passed to Junit's main
method. so you cannot use them in your test class. If you want to use some parameter in your test class, set a system parameter and retrieve it with System.getProperty(String)
in your code.
So the command line would look like this (you probably need to set other options like classpath):
java -Dfile.encoding=UTF-8 -Dmy.param=foo org.junit.runner.JUnitCore org.package.MyTest
For the working directory I would change to the desired directory with cd
before invoking JUnit.
Upvotes: 3