Skip to content

Support CSV headers in display names in parameterized tests #2759

@sbrannen

Description

@sbrannen

Overview

When using @CsvSource, CSV headers are not supported. With @CsvFileSource, the first n lines of each file can be skipped, which allows headers to be present in a CSV file but not used.

Ideally, one should be able to provide headers in a text block when using @CsvSource or in a file when using @CsvFileSource, and these headers can be used when generating the display name for each invocation of the @ParameterizedTest.

Proposal

This feature can be implemented using the Named API to associate each column value with its corresponding header.

Given the following parameterized test that sets useHeadersInDisplayName to true and uses {arguments} instead of {argumentsWithNames} for its display name pattern...

@ParameterizedTest(name = "[{index}] {arguments}")
@CsvSource(useHeadersInDisplayName = true, textBlock = """
	FRUIT,  RANK
	apple,  1
	banana, 2
	cherry, 3
	""")
void test(String fruit, int rank) {}

The generated display names are:

[1] FRUIT = apple, RANK = 1
[2] FRUIT = banana, RANK = 2
[3] FRUIT = cherry, RANK = 3

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions