10000 Multi-valued DataPoints methods are evaluated only once, but each single-valued DataPoint method is called once for each assignment · Issue #638 · junit-team/junit4 · GitHub
[go: up one dir, main page]

Skip to content
Multi-valued DataPoints methods are evaluated only once, but each single-valued DataPoint method is called once for each assignment #638
@pimterry

Description

@pimterry

(This is primarily a note for me to look into this more shortly, since I've come up against it in #639)

@DataPoints array methods are called once in AllMembersSupplier, and the values then reused for each theory.

Single DataPoint methods are instead called once for each possible assignment (for each unique and complete set of values for the given theory method)

This means that mutable values in DataPoints return values can be changed and then easily cause interactions between tests. Single DataPoint values can't though, and indeed there's a test specifically checking this (WithDataPointMethod.mutableObjectsAreCreatedAfresh).

Meanwhile field values are always reused (since they clearly can't be regenerated).

I think (debatable) both these datapoint method evaluation mechanisms should really be made to match instead, one way or the other, either by deferring array method execution somehow (quite complicated and hard to define), or by making single DataPoint values shared, as all other DataPoint values are.

I think (very very debatable) just running each DataPoint method once at the start and reusing all the values consistently is better myself (more intuitive to use, much simpler to implement). Datapoints also arguably really shouldn't be mutable in normal usage anyway. Finally users that do desire this behaviour can instead create a ParameterSupplier to support their specific instances of this case (where values must be regenerated) fairly simply: define a ParameterSupplier that returns a PotentialAssignment subclass where getValue() generates the new value in some way, rather than just returning the same one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0