anjandebnath / MockitoUnitTestTutorial

Mockito JUnit test

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unit test with Mockito

Ackwoledgement : This Project is created for getting familiar with Mockito JUnit test. This repository is created by taking reference from following links:

Custom template create for Junit4

From Android studio go to In the top menu, go to file > Settings and in the settings. In the left menu, find Editor > File and Code templates and click on the Code Tab and find Junit4 Test Class.

see here

  • Now its time to create a custom template for unit test
  • Just copy and paste this and get some pre defined imports and methods.
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.mockito.junit.MockitoJUnitRunner;
import static org.mockito.Mock.*;
import static org.mockito.Mockito.*;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.mockito.ArgumentCaptor.*;
import static org.mockito.ArgumentMatchers.*;



#parse("File Header.java")
@RunWith(MockitoJUnitRunner.class)
public class ${NAME} {

  //region constants
  
  //endregion constants
  
  //region helper fields
  
  //endregion helper fields

  ${CLASS_NAME} SUT;

  @Before
  public void setup() throws Exception{
      
     SUT = new ${CLASS_NAME} ();
     ${BODY}
  }
  
  //region helper methods
  
  //endregion helper methods
  
  //region helper classes
  
  //endregion helper classes
  
}

From where you start?

you will find the slides here

Find the documentation here

This will give you the basic idea about unit test.

start exploring the code from this sequence

under test package

  • LocatorTest
  • stub-> CustomerReaderTest
  • mock-> LateInvoiceNotifierTest
  • sync-> LoginUseCaseSyncTest
  • async-> DummyCallerTest

Thanks

Anjan Debnath

About

Mockito JUnit test


Languages

Language:Java 100.0%