I'm trying to use JunitParams in order to parametrized my tests. But my main problem is that the parameters are strings with special characters, tilde or pipe.
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
@RunWith(JUnitParamsRunner.class)
public class TheClassTest {
@Rule
public ExpectedException exception = ExpectedException.none();
@Test
@Parameters({"AA~BBB"})
public void shouldTestThemethod(String value) throws Exception {
exception.expect(TheException.class);
TheClass.theMethod(value);
// Throw an exception if value like "A|B" or "A~B",
// ie if value contain a ~ or a |
}
}
With tilde, I have no problem. But with pipe, I have an exception:
java.lang.IllegalArgumentException: wrong number of arguments
The pipe, as the comma, is used as a separator for parameters.
Is there any way for me to set a different separator? Or is this a limitation of JunitParams?
You can indeed escape the pipe with double backslashes:
@Parameters("AA\\|BBB")
public void test(String value)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With