Skip to content

Support @ExtendWith on fields #416

Closed

Description

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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