Skip to content

Introduce @FieldSource for parameterized tests #2014

@ktkopone

Description

@ktkopone

Overview

Introduce @FieldSource argument source for parameterized tests.

The feature is analogous to the existing @MethodSource support, except that the value of a named field is used as the source of arguments instead of the value returned by a factory method.

See #2014 (comment) and #2014 (comment) for examples.

Deliverables

  • Introduce @FieldSource and FieldArgumentsProvider.
    • Reject fields with Stream values.
    • Reject fields with Iterator values.
    • Support Supplier<T> fields where T is a type supported for @MethodSource.
    • Write unit and integration tests for preconditions, edge cases, etc.
    • Provide examples, etc. in class-level Javadoc for @FieldSource.
  • Document in the User Guide.
    • Provide examples for the User Guide.
  • Document in the Release Notes.

Original Issue Description

I understand that for memory/performance you probably want to recommend everyone use a Stream-returning method and @MethodSource, but given that an @ArraySource would be easier to use without having to convert all test data into methods, this would be a nice-to-have.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions