Send parameters from test suite to test case in junit 4

I have four cases of junit, and I need to pass them a parameter, the same for all of them, but this parameter is created dynamically in the test suite. How to pass a parameter from a test suite to all tests in a test case?

+7
source share
3 answers

If this is just a string parameter, you can set the system property and access it in test cases.

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

+1
source

Instead of using the system property, try using a static class, save the class with all the information you want in memory.

+1
source

Try parameterized tests. This is a built-in JUnit function designed to pass parameters to all tests inside a test case. See the link below for examples:

https://github.com/junit-team/junit4/wiki/Parameterized-tests

0
source

All Articles