1

给定一个简单的测试方法,注释为@ParameterizedTest,通过注释使用输入@CsvSource(例如@CsvSource({ "@", "*", "#", "?", "-", "$", "!", "0" })。在运行所述测试时,测试"#"会在应该测试时立即中断。阅读堆栈跟踪/异常时,我发现以下内容:

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

我猜问题出在最后一个块(Comment character=#)中:特定参数被作为注释读取。如何更改此设置?

4

1 回答 1

0

您不能更改注释字符。

可以#像这样用单引号括起来:

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

但你实际上不应该使用@CsvSource单个字符串。

相反,只需使用以下内容:

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

于 2018-08-01T09:09:11.370 回答