JUnit Mockito example And Mockito framework

  <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
//add() method is provided by   external team. 
public int perform(int i, int j)
{
return service.add(i,j)*2;
}
public interface CalculatorService {
public int add(int i, int j);
}
CalculatorService calService= Mockito.mock(CalculatorService.class);
when(calService.add(2, 3)).thenReturn(5);

--

--

Software Automation Testing expert with 9 years of work experience in diverse tools and technologies.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store