Unit testing

We use unit tests to verify the individual code components as an independent unit without any external dependencies, mocking all the dependencies required. When we say testing the unit, this refers to testing a class and its functions. The response of all the functions of different classes and third-party libraries, if any, has to be mocked. We will write the test case for that particular class only. Here, the focus is on covering the test cases for a single class.

Let's write a unit test for our createPerson() function in the PersonController class.

We add the following dependencies to our identity-service module with a test scope for the purpose of unit testing the code:

        <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito-core}</version>
<scope>test</scope>
</dependency>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset