1

Given a simple test-method, annotated as @ParameterizedTest, employing input via Annotation @CsvSource (e.g.@CsvSource({ "@", "*", "#", "?", "-", "$", "!", "0" }). When running said test, the test interrupts as soon as "#" is supposed to be tested. When reading through the stacktrace/exception, I found the following:

org.junit.jupiter.params.shadow.com.univocity.parsers.common.TextParsingException: java.lang.IllegalArgumentException - Unable to skip 1 lines from line 2. End of input reached
  Parser Configuration: CsvParserSettings:
    ...
    CsvFormat:
      Comment character=# 
      Field delimiter=,
      Line separator (normalized)=\n
      Line separator sequence=\r\n
      Quote character='
      Quote escape character='
      Quote escape escape character=null

I guess the problem is in the last block (Comment character=#): The specific parameter is being read as comment. How do I change this setting?

Navid Noor
  • 13
  • 3

1 Answers1

0

You cannot change the comment character.

You could wrap the # in single quotes like this:

@CsvSource({ "@", "*", "'#'", "?", "-", "$", "!", "0" })

But you actually shouldn't be using @CsvSource for single strings anyway.

Instead, simply use the following:

@ValueSource(strings = { "@", "*", "#", "?", "-", "$", "!", "0" })

Sam Brannen
  • 29,611
  • 5
  • 104
  • 136
  • Thank you! Tried many ways of escaping the `#`, surprised that it were single quotes. This also works for an input beginning with `#`, and tailed with multiple subsequent characters, e.g. `#abc` (which also leads to the interruption of the testcase, for anyone that's interested). Do you know why this works, by chance? – Navid Noor Aug 01 '18 at 13:24
  • If you wrap `#` in single quotes, the first character is `'` instead of `#`. So the text is then no longer interpreted as a comment. – Sam Brannen Aug 02 '18 at 10:52