send parameters from test suite to test case in junit 4

Alexander Herrera picture Alexander Herrera · Sep 21, 2011 · Viewed 7.9k times · Source

I've got four junit cases and I need to pass them a parameter, that is the same for all of them, but this parameter is created in a dynamic way in the test suite. How can I pass a parameter from the test suite to all the tests in the test case?

Answer

kdabir picture kdabir · Sep 21, 2011

If its just a string parameter, you can set the System Property and access it in test cases.

If you want to programmatically do it, you can do it at one place System.setProperty("x","123"); otherwise you can always pass System properties from command line as -Dx=123.