0% found this document useful (0 votes)
15 views4 pages

Testing Service Layer Lecture Notes

The document outlines the process of testing the service layer of a Spring Boot application, specifically focusing on the EmployeeService class. It covers the creation of unit tests using Mockito, including methods for saving, retrieving, updating, and deleting employee records. Additionally, it introduces JUnit testing in a Behavior-Driven Development (BDD) style with a specific syntax example.

Uploaded by

Sourabh Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

Testing Service Layer Lecture Notes

The document outlines the process of testing the service layer of a Spring Boot application, specifically focusing on the EmployeeService class. It covers the creation of unit tests using Mockito, including methods for saving, retrieving, updating, and deleting employee records. Additionally, it introduces JUnit testing in a Behavior-Driven Development (BDD) style with a specific syntax example.

Uploaded by

Sourabh Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Spring Boot Applicatio

Service Layer Testing


By Ramesh Fadatare (Java Guides)

Spring Boot Application


Service Layer Testing

Controller Service Repository


DB
Layer Layer Layer

Mockito

Service Layer Testin


1.Create EmployeeService with saveEmployee method
2.Quick Recap of Mockito basics (before writing Unit tests)
3.Unit test for EmployeeService saveEmployee method
4.Using @Mock and @InjectMocks annotations to mock the object
5.Unit test for saveEmployee method which throws Exception
6.Unit test for EmployeeService getAllEmployees method - Positive Scenario
7.Unit test for EmployeeService getAllEmployees method - Negative Scenario
8.Unit test for EmployeeService getEmployeeById method
9.Unit test for EmployeeService updateEmployee method
10.Unit test for EmployeeService deleteEmployee method
g

JUnit tests in BDD Style


Syntax Example

@Test
public void given_when_then() {
// given - precondition or setup

// when - action or the behaviour we’re testing

// then - verify the output


}

You might also like