java - Difference between @Mock and @InjectMocks -


what difference between @mock , @injectmocks in mockito framework?

@mock creates mock. @injectmocks creates instance of class , injects mocks created @mock (or @spy) annotations instance. note must use @runwith(mockitojunitrunner.class) or mockito.initmocks(this) initialise these mocks , inject them.

@runwith(mockitojunitrunner.class) public class somemanagertest {      @injectmocks     private somemanager somemanager;      @mock     private somedependency somedependency; // injected somemanager       //tests...  } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -