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
- Support programmatic extension registration via fields #497
- Introduce mechanism for programmatic extension management #506
- Support declarative extension registration on fields and parameters #864
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 commentedon Jul 22, 2016
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.
[-]Question: Composed annotations with @ExtendWith on fields[/-][+]Support @ExtendWith on fields[/+]sbrannen commentedon Sep 2, 2016
Overhauled this issue's description by introducing Status Quo, Proposal, and Deliverables sections with a new focus on programmatic extension registration via fields.
sbrannen commentedon Sep 2, 2016
Currently slated for M3.
17 remaining items