【发布时间】:2015-09-25 14:44:12
【问题描述】:
我正在尝试使用 JunitParams 来参数化我的测试。但我的主要问题是参数是带有特殊字符的字符串,波浪号或管道。
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 |
}
}
使用波浪号,我没有问题。 但是对于管道,我有一个例外:
java.lang.IllegalArgumentException: wrong number of arguments
管道,作为逗号,用作参数的分隔符。
我有什么方法可以设置不同的分隔符吗? 还是这是 JunitParams 的限制?
【问题讨论】:
-
你可以使用this syntax来解决问题
-
我也会尝试用“\\”转义管道,请参阅this sample
-
我试过这个语法,还是不行。现在我使用参数化而不是 JunitParams。它正在工作,但论点适用于所有 JunitClass (所以我必须创建一个新类)。作品。但是因为我的参数很难阅读(充满 | 和 ~ 和其他特殊字符),我不想在我的输入集中添加很多转义字符。但是,是的,它正在工作。
标签: java junit pipe comma junitparams