
Learn to implement unit and integration testing for Spring Boot applications using JUnit, Mockito, and test containers, guided by a practical Spring Boot framework.
Overview of course sections for developing real-time Spring Boot unit and integration testing, including environment setup, base project creation, and tests with JUnit, Mockito, and test containers.
Install the appropriate JDK version for your Spring Boot, choose an IDE like IntelliJ, install Docker for test containers, and import a MySQL database.
Download JDK 11 for Windows and run the installer. The video guides accessing oracle.com, selecting the Windows download, and completing the JDK 11 installation.
Download and install IntelliJ IDEA 2022 on Windows, choosing the free Community Edition, and follow the setup steps from browser download to completion with a desktop shortcut.
Download the MySQL community edition and install the server on Windows, running the installer as administrator. Then open MySQL Workbench to create a test schema and run queries.
Review the business requirements, use case diagram, and system roles administrator, instructor, and student for the Java Corner Admin backend, and map wireframes and UML class diagram to the database.
Clarifies business requirements and designs a back-end dashboard with courses, instructors, and students modules, secured by admin, instructor, and student roles via Spring, JWT, and an Angular front end.
Identify admin, instructor, and student roles in the Java Corner admin system, review wireframes and screens, and outline how business requirements guide database design, security rules, and application flow.
Create a UML class diagram for an online courses site, modeling course, instructor, student, user and role, with many-to-many enrollments and an association class linking courses and students.
Test the final online courses app across admin, instructor, and student roles, featuring login, course management, profile updates, enrollments, and role based access.
Open the spring service base project, create a new database with phpMyAdmin, then run the project to generate tables from annotations for real-time Spring Boot testing.
Explore setting up Spring Boot unit tests for the service layer by validating load course by ID with JUnit and Mockito, including mocking the DAO and handling not found exceptions.
Explore unit testing of the core course service in Spring Boot, covering create and update, assign student to course, fetch all, fetch courses for student, and remove course, with mocks.
Learn to unit test the instructor service in Spring Boot with JUnit and Mockito, covering load by id, find by name, load by email, and create instructor with mocks.
Perform unit tests for the remaining instructor service methods, including update, fetch instructors, and remove instructor, verifying save and delete calls and removal of related courses.
Execute unit tests for the role service implementation by injecting a mock for the role dao with the Mockito extension. Verify load roll by name and create roll interactions.
Develop and validate the user service through unit tests, using mocks for the user DAO, testing load by email, create user, and assign roles to user.
Develop and implement unit tests for the student service implementation with mockito, covering load by id, not found exception, find by name, and load by email.
Complete the unit testing for the student service by validating create, update, find all, and remove operations, with mocks for user service and integration with test containers.
Explore configuring test containers for real-time Spring Boot tests, add test container and MySQL dependencies in pom.xml, and prepare a dedicated test database for integration testing.
Create a dedicated MySQL docker container for testing in a real-time Spring Boot unit and integration test setup, wiring the container URL, username, and password via dynamic properties before tests.
Generate an initial data script to reload dev and testing databases and create a clear all script to wipe data before tests in a spring boot environment.
Develops course dao integration tests using data jpa with a mysql test container, initializes data with sql scripts, and validates find by course name contains and by student id.
Develop instructor dao integration tests in a spring boot project using data jpa test with a MySQL test container, replacing in-memory database and validating find by name and by email.
Conduct role dao integration tests by loading data with sql, using data jpa test and a mysql container, and verify find by name returns role or null for non existing.
Structure and execute integration tests for the user dao using data JPA test and a MySQL container, validating find by email and handling non-existent emails with assertions.
Develop student dao integration tests by configuring data tests, auto configuring the test database, and sql init scripts, then verify find by name and email, and note future container reuse.
Reuse the same MySQL container for all integration tests by enabling test containers reuse, speeding runs, and confirming a successful test connection to the database.
Explore how the real-time spring boot unit and integration testing project structures JPA entities, DAO interfaces, service layer logic, and tests with a dockerized MySQL database.
Spring Boot :
Is the most popular framework for building enterprise Java applications. Spring Boot includes testing support to develop unit tests and integration tests using JUnit, Mockito and MockMvc. By developing tests, you can create applications with better code design, fewer bugs, and higher reliability. This course shows you how to take full advantage of Spring Boot's testing support.
JUnit :
Develop JUnit Tests
Set up projects to use JUnit
Apply JUnit assertions: Equals/Not Equals and Null/NotNull
Apply JUnit assertions: Same/Not Same and True/False
Leverage JUnit lifecycle annotations
Define custom display names for JUnit tests
Check for exceptions and timeouts
Define execution order in JUnit tests
Perform code coverage analysis for JUnit tests
Apply conditionals with JUnit tests
Test Driven Development (TDD) :
Apply Test Driven Development for build tests and application code.
Create a failing test first.
Update your code to make the tests pass.
Take your tests from RED to GREEN.
Apply TDD to a coding project.
Leverage parameterized tests with TDD.
Mocking with Mockito :
Identify the need for mocking during test development
Leverage Mockito in JUnit tests
Applying the @MockBean annotation for injection
Throwing exceptions with Mocks
Database Integration Testing :
Identify the need for database integration testing during test development
Add database setup and clean code using @BeforeEach and @AfterEach
Leverage an embedded database to ease with testing setup and maintenance.