Skip to content

Support @ExtendWith on fields #416

Closed
@slu-it

Description

@slu-it

Overview

Is it planned for JUnit 5 to discover composed @ExtendWith annotations on fields?

As far as I can see (from Milestone 1) they are only discovered in case they are used on types or methods.

For projects like Mockito it would be useful to also discover extension by analyzing field annotations.

Example:

// The following explicit declaration would become unnecessary.
// @ExtendWith(MockitoExtension.class)
public class MyServiceTest {

    @Mock
    FooService fooService;

    @InjectMocks
    MyService cut;

    @Test
    void testSomething() {
        ....
    }

}

In case @Mock and @InjectMocks were to be changed to composed annotations declaring @ExtendWith(MockitoExtension.class), they could simply be used without having to declare the extension for each test class.

Related Issues

Deliverables

  • Support registration of extensions on fields with the desired extension classes supplied via @ExtendWith(...).
    • This is analogous to the current support for declaring @ExtendWith on classes and methods.

Activity

sbrannen

sbrannen commented on Jul 22, 2016

@sbrannen
Member

Discovery of extensions on fields is something we have in fact considered, but the feature is not currently planned. So I'll put it in the backlog now.

Thanks for raising the issue.

added this to the 5.0 Backlog milestone on Jul 22, 2016
changed the title [-]Question: Composed annotations with @ExtendWith on fields[/-] [+]Support @ExtendWith on fields[/+] on Jul 22, 2016
self-assigned this
on Sep 2, 2016
modified the milestones: 5.0 M3, 5.0 Backlog on Sep 2, 2016
sbrannen

sbrannen commented on Sep 2, 2016

@sbrannen
Member

Overhauled this issue's description by introducing Status Quo, Proposal, and Deliverables sections with a new focus on programmatic extension registration via fields.

sbrannen

sbrannen commented on Sep 2, 2016

@sbrannen
Member

Currently slated for M3.

removed their assignment
on Sep 8, 2016

17 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sbrannen@slu-it

        Issue actions

          Support @ExtendWith on fields · Issue #416 · junit-team/junit5