Skip to content

Introduce extension API for modifying ParameterizedTest arguments #4753

@scottjasso

Description

@scottjasso

#1139 was recently fixed, allowing access to ParameterInfo for parameterized tests. However some functionality was intentionally left out:

Changing the array would cause the test method to be called with changed arguments.

I don't think that is a good idea. As far as I can tell, nobody has requested to be able to change the arguments provided to a test method. Thus, I would rather pass a copy of the arguments array to such an extension.

If the community clamors for such support, we could always change that aspect at a later date.

I would like to change the arguments :)

My use case is using junit with kotlin. We have a custom extension for injecting a "TestEnv", passed as a receiver:

@Test
@MyTestExtension
fun TestEnv.testFoo() { ... }

This becomes very difficult with @ParameterizedTest, which always wants to put the arguments first. So instead you need this, which is quite ugly.

@ParameterizedTest
@MyTestExtension
@MethodSource("blah")
fun testFoo(arg: String, testEnv: TestEnv) {
  with(testEnv) {
    ...
  }
}

It would be nice if I could modify the arguments to put the TestEnv first. Some kind of general way to modify the results of ArgumentProviders would be neat.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions