Hello,
We use Mockito in our projects a lot and lately I've been having an idea about adding a method that allows to get all mocks for a test method. Looks something like this:
@ExtendWith(MockitoExtension.class)
class TestClass {
@Mock
Object mock1;
Object mock2;
@BeforeEach
void init() {
mock2 =
mock(Object.class);
}
@Test
void compareFailTest() {
//setup
Object mock3 =
mock(Object.class);
//run
//...
//verify
//...
Object[] mocks = Mockito.getCurrentMocks(); //[mock1, mock2, mock3]
Mockito.
verifyNoMoreInteractions(mocks);
}
}
I would be happy to participate in the implementation.
Sorry if this has already been brought up by someone and rejected - tried to find a conversation on the topic and did not.
Thanks!