Skip to content

Add possibility to set ParametersRunnerFactory programatically. #1180

Open
@rhopp

Description

@rhopp

I want to be able to create my own runners for parameterized tests. This was possible, when PR #564 was merged.
This was reworked in #773, so that user can use @RunWiht(Parameterized.class) followed by @UseParametersRunnerFactory. This is fine for simple scenarios.
Our scenario is as follows:
We have class extending Suite (let's call it SuperSuite), which reads some configuration and creates runners for each class in that suite, if it satisfies that configuration(we don't want some classes to be run with some configurations and vice versa). The tree of runners looks like this:

SuperSuite
 |___Config1Runner
 |        |____Class1
 |        |          |____method1
 |        |          |____method2
 |        |____Class2
 |                  |____method1
 |                  |____method2
 |___Config2Runner
         |____Class1
         |          |____method1
         |          |____method2
         |____Class2 (skipped, did not meet configuration requirement)

Now I want to implement mechanism of parameterized classes. Let's say I want Class 1 to be parameterized. The tree would look something like this:

SuperSuite
 |___Config1Runner
 |        |____Class1 -parameterized
 |        |          |____Class1 -param1
 |        |          |            |____method1
 |        |          |            |____method2
 |        |          |____Class1 -param2
 |        |          |            |____method1
 |        |          |            |____method2
 |        |          |____Class1 -param3
 |        |                       |____method1
 |        |                       |____method2
 |        |____Class2
 |                  |____method1
 |                  |____method2
 |___Config2Runner
         |____Class1 -parameterized
         |          |____Class1 -param1
         |          |            |____method1
         |          |            |____method2
         |          |____Class1 -param2
         |          |            |____method1
         |          |            |____method2
         |          |____Class1 -param3
         |                       |____method1
         |                       |____method2
         |____Class2 (skipped, did not meet configuration requirement)

I hope I described my intentions clearly.

With current situation I was almost able to do it:
I added @UseParametersRunnerFactory(MyFactory.class) annotation to Class1 and in the SuperSuite I've created the Parameterized programatically for classes annotated with
@UseParametersRunnerFactory. Unfortunately I need to pass some parameters to my MyFactory to be able to correctly create child runners (This is the part I'm unable to do right now).

Now for solutions:
With PR #564, the solution would be pretty simple. I would just create my own Parameterized suite (extending Parameterized) overriding createRunner method.

Or... Put back constructor protected Parameterized(Class<?> klass, ParametersRunnerFactory runnerFactory) from PR #773.

I hope I made myself clear and sorry for the long post.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions