Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using "Comma" or "pipe" within JunitParams

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?

like image 201
GaspardP Avatar asked Sep 25 '15 14:09

GaspardP


1 Answers

You can indeed escape the pipe with double backslashes:

@Parameters("AA\\|BBB")
public void test(String value)
like image 188
Per Huss Avatar answered Sep 30 '22 14:09

Per Huss