Skip to content

Pass test Method to TestInstanceFactory when using Lifecycle.PER_METHOD #1568

Closed as duplicate of#3445
@seanf

Description

@seanf

I'm trying to update CDI-Unit to support JUnit 5, specifically CDI-Unit's ProducerConfig feature for JUnit 4 which uses annotations on the test method to help configure the deployment payload for Weld. Weld is then used to construct test instances. This can almost be replicated in JUnit 5, by implementing a TestInstanceFactory. (Obviously this won't be compatible with Lifecycle.PER_CLASS, because the instances must allow for per-method configuration.)

The problem is, when TestInstanceFactory.createTestInstance() is called, extensionContext.getTestMethod() always returns Optional.empty(), even when using Lifecycle.PER_METHOD.

If the TestInstanceFactory were to receive the test Method, when using Lifecycle.PER_METHOD, it would be possible to use annotations from the test method to control test instance creation, thus allowing features like ProducerConfig to be created.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions