Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test parameters are not properly escaped in test names #152

Open
dimas opened this issue Mar 8, 2018 · 0 comments
Open

Test parameters are not properly escaped in test names #152

dimas opened this issue Mar 8, 2018 · 0 comments

Comments

@dimas
Copy link

dimas commented Mar 8, 2018

The testnames generated by JUnitParams do not escape special characters.
When these parameters

    public static Object[][] escapeSequences() {
        return new Object[][]{
//...
                {"X"},
                {"\b"},  //   \b => backspace
                {"\f"},  //   \f => formfeed

are fed into through

    @Test
    @Parameters(method = "escapeSequences")
    public void testEscaping(final String text) {
    }

The test works as it should but the XML report generated by JUnit fails to be parsed by majority of XML parsers because these characters just go into the test case name. In the file target/surefire-reports/TEST-test.JsonParserTest.xml I can see:

  <testcase name="testEscaping(X) [2]" classname="test.JsonParserTest" time="0"/>
  <testcase name="testEscaping() [3]" classname="test.JsonParserTest" time="0"/>
  <testcase name="testEscaping(^L) [4]" classname="test.JsonParserTest" time="0"/>

I cannot copypaste it properly but there is actually a character with code 08 on the second line and 0A on the last. Each making XML invalid.

You can argue that it is is JUnit that does not do proper escaping when writing XML but it probably just does not expect test names (which used to be just method) names to contain anything like that.

After all, if your parameter is of type String I would expect it to go as a proper Java string into the test name - quoted and with every character that should be escaped in Java string to be escaped:

  <testcase name="testEscaping("X") [2]" classname="test.JsonParserTest" time="0"/>
  <testcase name="testEscaping("\b") [3]" classname="test.JsonParserTest" time="0"/>
  <testcase name="testEscaping("\f") [4]" classname="test.JsonParserTest" time="0"/>

Cheers

PS: reproduced with 1.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant