Open
Description
Description
I am writing unit tests where test cases have input strings with (non-printable) control characters. These characters generally occupy code points U+0000 through U+001F. When using @CsvSource
I am finding that using control character literals in strings behaves differently from printable characters.
For example:
- An unquoted
\u0000
literal is translated tonull
. - A quoted
\u0000
literal is translated to an empty string""
.
This behavior is observed with both Eclipse's internal JUnit 5 test runner and with Maven's Surefire plugin. I have considered the possible impact of the nullValues
parameter of @CsvSource
. This attribute defaults to {}
, so translation to null
or an empty string is therefore not expected.
Steps to reproduce
The test below should pass, but unexpectedly fails for @CsvSource
test cases that have \u0000
literals.
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
class Reproduction {
@Test
void proveThatStringWithControlCharacterLiteralIsNotNullAndHasLenghtOfOne() {
assertEquals(1, "\u0000".length());
}
@ParameterizedTest
@CsvSource(delimiterString = "||", textBlock = """
A || 1
\u0000 || 1
B\u0000 || 2
""")
void testWithUnquotedInput(String testcase, Integer expectedLength) {
assertNotNull(testcase);
assertEquals(expectedLength, testcase.length());
}
@ParameterizedTest
@CsvSource(delimiterString = "||", textBlock = """
'A' || 1
'\u0000' || 1
'B\u0000' || 2
""")
void testWithQuotedInput(String testcase, Integer expectedLength) {
assertNotNull(testcase);
assertEquals(expectedLength, testcase.length());
}
}
Context
Used versions
- Jupiter 5.11.0-M2
- Platform 1.11.0-M2
Build Tool/IDE
- Eclipse 2024.03
- Maven 3.9.6
- JVM: Java HotSpot(TM) 64-Bit Server VM (build 17+35-LTS-2724, mixed mode, sharing)