Testing e QA Java Unit Testing

Complete Java Testing: JUnit 5, Mockito and Spring Boot (Practical Backend Guide)

Complete Java testing: JUnit 5, Mockito, Spring Boot integration tests, MockMvc and InMemory database.

Course description

Test Your Java Applications Like a Professional

Writing code that works is not enough — you need to know that it works. This course takes you from zero to professional testing in Java with JUnit 5, Mockito and Spring Boot, covering all levels: unit tests, integration tests and REST Controller testing with MockMvc.

What You'll Learn

  • What the Testing Pyramid is and the difference between Unit, Integration and E2E tests
  • Maven project setup with JUnit 5 (Jupiter)
  • Assertions: assertEquals, assertTrue, assertThrows and all variants
  • @BeforeAll vs @BeforeEach: correct test initialization
  • @ParameterizedTest: avoid duplication with @ValueSource and @CsvSource
  • Mockito: mocking Repositories, when().thenReturn(), dynamic behavior
  • Stub vs Mock vs Spy: real differences with practical examples
  • REST Controller testing with @WebMvcTest and MockMvc
  • @WebMvcTest vs @SpringBootTest: when to use which
  • Integration Tests with @SpringBootTest and InMemory database
  • Database reset between tests to avoid dirty data
  • Service testing with Mockito in isolation (without Spring Boot)
  • Controller testing with @MockBean and MockMvc

From the First Test to a Complete System

The course follows a logical progression: you start from basic assertions and end up testing an entire REST API with real integration tests. Every concept is explained with concrete examples and immediately applied in a working project.

Who It's For

Java and Spring Boot developers who want to build a professional test suite and stop testing manually. Basic knowledge of Spring Boot required.

Lessons list

Let's start from the foundations of Java testing: the difference between Unit Tests, Integration Tests, and End-to-End tests, and how the Testing Pyramid works. The ideal starting point for structuring a professional test suite with JUnit 5.

Guarda lezione

Let's create a Maven project from scratch and integrate JUnit 5 (Jupiter) with the correct dependencies. I'll show you the test project structure and how to configure pom.xml to start writing your first Java tests.

Guarda lezione

Let's write the first JUnit 5 test together: test structure, the @Test annotation, how to run the test, and how to read the results. The practical starting point for understanding the basic Java testing flow.

Guarda lezione

Let's get into the heart of testing with JUnit 5 assertions: assertEquals, assertTrue, assertFalse, assertNull, assertNotNull, and assertThrows for verifying exceptions. Understanding assertions means writing tests that actually give you useful information.

Guarda lezione

I'll explain the difference between @BeforeAll and @BeforeEach in JUnit 5: when to use each, how to manage state initialization in tests, and the common mistakes that make tests fragile or non-deterministic.

Guarda lezione

Let's eliminate test code duplication in JUnit 5 with @ParameterizedTest — I'll show you how to use @ValueSource and @CsvSource to run the same test with different data, keeping the suite clean and scalable.

Guarda lezione

I'll introduce Mockito for isolating dependencies in Java tests: what a mock is, why you shouldn't test the database directly, and how to simulate a Repository. The first concrete step toward unit tests truly isolated from persistence.

Guarda lezione

Let's go deeper into Mockito with when().thenReturn(): I'll show you how to control mock behavior, simulate different scenarios, and manage dynamic responses to write Java tests that are truly isolated from real dependencies.

Guarda lezione

I'll clarify once and for all the difference between Stub, Mock, and Spy in Mockito, with practical examples. Understanding these three concepts is the key to using Mockito professionally and precisely in Java tests.

Guarda lezione

Let's start testing Spring Boot REST Controllers: I'll show you what @WebMvcTest is, how to use MockMvc to simulate HTTP calls in tests, and how to verify responses without starting the full application context.

Guarda lezione

Let's go deeper into REST Controller testing with MockMvc: verifying HTTP status codes, handling 404 and 500 error cases, and validating JSON responses for complete, realistic Spring Boot tests.

Guarda lezione

Let's close out the REST Controller testing cycle with complete examples and best practices: how to structure tests in a real Spring Boot project to have an organized, readable, and easily maintainable test suite.

Guarda lezione

I'll clarify the difference between @WebMvcTest and @SpringBootTest in Spring Boot: test slice vs full test, when each is the right choice, and the practical implications for execution speed and isolation.

Guarda lezione

Let's build a realistic test environment with an in-memory database in Spring Boot: why to avoid the real database in tests, how to configure H2, and how to structure the project for reliable and repeatable integration tests.

Guarda lezione

Let's build a complete backend flow with Service and Controller in Spring Boot without DTOs, focusing on application logic and testing the system's real behavior before adding abstraction layers.

Guarda lezione

Let's write a real Integration Test with @SpringBootTest: I'll test the entire User API flow, from Spring Boot context startup to verifying real responses, without isolating components with mocks.

Guarda lezione

Let's take Integration Tests with @SpringBootTest to an advanced level: realistic scenarios, edge case testing, and verifying application behavior beyond the simple 'works / doesn't work' check.

Guarda lezione

One of the most common mistakes in Integration Tests: dirty data between test runs. I'll show you how to isolate each test with @SpringBootTest, avoid side effects, and guarantee always-reliable results.

Guarda lezione

Let's get back to isolated testing: I'll verify the Service's business logic with Mockito without starting the Spring Boot context or using a real database. The fastest and cleanest way to test Java business logic.

Guarda lezione

Let's test the Controller in isolation with @MockBean and MockMvc — we'll simulate the Service behavior without a real database, focusing exclusively on the REST layer and the HTTP behavior of the Spring Boot Controller.

Guarda lezione
Giovanni Pace

Giovanni Pace

Ingegnere Informatico · Pratola Peligna

  • 107 Courses
About the teacher

Sono un ingegnere informatico con oltre 15 anni di esperienza nel settore ICT. Mi occupo di sviluppo software, cybersecurity, data science e intelligenza artificiale, con particolare attenzione all’innovazione e all’automazione dei processi aziendali. Da anni svolgo anche attività di docenza e formazione, creando percorsi pratici e coinvolgenti su programmazione, DevOps, AI e sicurezza informatica.

This course includes

  • Lessons 20
  • Duration 4h 0m
  • Difficulty intermedio
  • Language it
  • Certificate No

Recently viewed