Search code examples
javaparametersjunitjunit-rule

JUnit @Rule to pass parameter to test


I'd like to create @Rule to be able to do something like this

@Test public void testValidationDefault(int i) throws Throwable {..}

Where i is parameter passed to the test by @Rule.

However I do get

java.lang.Exception: Method testValidationDefault should have no parameters

is there any way to bypass it and set the i parameter in the @Rule?


Solution

  • it can't be done, you can't pass parameters to test method even using @Rule.