JUnit 参数化测试显示换行符

JUnit Parameterized Tests Display Newline

这是 JUnit Parameterized Tests will silently fail if you attempt to display a newline character: https://bugs.eclipse.org/bugs/show_bug.cgi?id=474465

的一个已知错误
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

@RunWith(Parameterized.class)
public class Example {

    private String actual;
    private String expected;

    public Example(String actual, String expected) {
        this.actual = actual;
        this.expected = expected;
    }

    @Parameters(name = "{0}") // can't do this ("\n" not allowed)
    public static Collection<Object[]> testCollection() {
        return Arrays.asList(new Object[][] {
            { "Hello\nWorld", "Hello\nWorld" }
        });
    }

    @Test
    public void test() {
        assertEquals(expected, actual);
    }

}

是否有任何已知的解决此问题的方法?例如,有没有办法在这里替换换行符:@Parameters(name = "{0}"),但实际上在测试本身没有?

你需要双转义斜杠,比如\n