Skip to content

przemyslawj/mockito-intellij-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Plugin

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

Examples

Before code generation

import org.junit.Test;

class FooTest {

    @Test
    public void testFoo() throws Exception {
        
    }

}

After code generation

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 {

    }
}

Plugin Usage

To generate the Mockito code with the plugin hit ctrl shift M or use a choose the action from "Generate Action" context menu.

About

Plugin generating boilerplate Mockito code in unit tests

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages