Possible Duplicate:
@parameters method is executed before @beforeclass method
I am facing some trouble with JUnit 4 TestsUites and Parameterized Tests.
In my Suite I want to set a SystemProperty like this:
@RunWith(Suite.class)
@SuiteClasses({ParameterizedTestCase.class })
public class TestSuite {
@BeforeClass
public static void setUpSuite() {
System.out.println("suite");
System.setProperty("propertyToSet", "propertyToSet");
}
}
In the ParameterizedTestCase I declared the generateParams() to print the Property like this:
@RunWith(Parameterized.class)
public class ParameterizedTestCase{
@Parameters
public static Collection<Object[]> generateParams() {
System.out.println("Parameter: " + System.getProperty("propertyToSet"));
}
@Test
public void testSomething() {
//doSometing
}
}
The Output i get is as follows:
Parameter: null
suite
So the Methods are invoked in the wrong order. I thought, that the BeforeClass of the Suite is invoked before all TestClasses.
How can I fix this problem. I need to set a Parameter in the Suite, which will be used by several TestCases. But the TestCases don't know from which Suite they are invoked. So I prefer something like a Systemproperty.
Thanks for your Help
Kirschmichel