I stopped supporting the plugin, please feel free to fork the project. Please consider using https://plugins.jetbrains.com/plugin/12833-junit-5-mockito-code-generator as an alternative.
Intellij plugin for generation of Mockito code in unit tests
The following code elements are auto-generated by the plugin
@RunWith(MockitoJUnitRunner.class)
annotation for the class- Mocked fields for each non-static object declared in the test subject
- Field for the test subject with
@InjectMocks
annotation - static imports for useful mockito functions like
when
,verify
import org.junit.Test;
class FooTest {
@Test
public void testFoo() throws Exception {
}
}
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)
class FooTest {
@Mock
private Random random;
@InjectMocks
private Foo underTest;
@Test
public void testFoo() throws Exception {
}
}
To generate the Mockito code with the plugin hit ctrl shift M
or use a choose the action from
"Generate Action" context menu.