user793623
user793623

Reputation:

How do I pass an argument to a JUnit Test?

I would like to pass arguments to my JUnit tests from run configurations. How do I reach to JUnits main method to access to those args? Anybody knows how to do this?

thanx

Upvotes: 2

Views: 1294

Answers (1)

bobbypavan
bobbypavan

Reputation: 548

You can run you unit test with -D system properties and access them from you test case with System.getProperty instead of the way you are asking. Or check the class JUnitCore main method, that is used to run a test case from command line. http://junit.sourceforge.net/javadoc/org/junit/runner/JUnitCore.html. But never done this before.

I am not sure what kind of values you intend to pass, but in general it will be good to not have your tests depend on some data passed as arguments so that your tests are self contained and easy to run.

Upvotes: 3

Related Questions