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

Support CSV headers in display names in parameterized tests #2759

Closed
sbrannen opened this issue Oct 29, 2021 · 1 comment
Closed

Support CSV headers in display names in parameterized tests #2759

sbrannen opened this issue Oct 29, 2021 · 1 comment

Comments

@sbrannen
Copy link
Member

sbrannen commented Oct 29, 2021

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
@sbrannen sbrannen added this to the 5.9 M1 milestone Oct 29, 2021
@sbrannen sbrannen self-assigned this Oct 29, 2021
@sbrannen sbrannen changed the title Use CSV header names in display names in parameterized tests Support CSV header names in display names in parameterized tests Oct 29, 2021
@sbrannen sbrannen changed the title Support CSV header names in display names in parameterized tests Support CSV headers in display names in parameterized tests Oct 29, 2021
sbrannen added a commit that referenced this issue Oct 29, 2021
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.1415926535
	""")
void test(String fruit, double rank) {}

The generated display names are:

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

See #2759
sbrannen added a commit that referenced this issue Oct 29, 2021
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

See #2759
sbrannen added a commit that referenced this issue Oct 29, 2021
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

See #2759
sbrannen added a commit that referenced this issue Oct 30, 2021
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

See #2759
@sbrannen sbrannen modified the milestones: 5.9 M1, 5.8.2 Nov 2, 2021
@sbrannen
Copy link
Member Author

sbrannen commented Nov 2, 2021

Superseded by #2767.

@sbrannen sbrannen closed this as completed Nov 2, 2021
@sbrannen sbrannen removed this from the 5.8.2 milestone Nov 2, 2021
sbrannen added a commit to sbrannen/junit5 that referenced this issue Nov 19, 2021
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

See junit-team#2759
sbrannen added a commit that referenced this issue Nov 19, 2021
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

See #2759
sbrannen added a commit that referenced this issue Nov 19, 2021
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

See #2759
runningcode pushed a commit to runningcode/junit5 that referenced this issue Feb 15, 2023
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

See junit-team#2759
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants